Commit ae3d250a authored by Markus Koller's avatar Markus Koller

Use defined HTTP errors in WebHookService

This is a simple refactoring to reuse the list of exceptions defined
in `Gitlab::HTTP::HTTP_ERRORS`.
parent 2280f026
...@@ -69,8 +69,7 @@ class WebHookService ...@@ -69,8 +69,7 @@ class WebHookService
http_status: response.code, http_status: response.code,
message: response.to_s message: response.to_s
} }
rescue SocketError, OpenSSL::SSL::SSLError, Errno::ECONNRESET, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, rescue *Gitlab::HTTP::HTTP_ERRORS,
Net::OpenTimeout, Net::ReadTimeout, Gitlab::HTTP::BlockedUrlError, Gitlab::HTTP::RedirectionTooDeep,
Gitlab::Json::LimitedEncoder::LimitExceeded, URI::InvalidURIError => e Gitlab::Json::LimitedEncoder::LimitExceeded, URI::InvalidURIError => e
execution_duration = Gitlab::Metrics::System.monotonic_time - start_time execution_duration = Gitlab::Metrics::System.monotonic_time - start_time
log_execution( log_execution(
......
...@@ -128,11 +128,10 @@ RSpec.describe WebHookService do ...@@ -128,11 +128,10 @@ RSpec.describe WebHookService do
end end
it 'handles exceptions' do it 'handles exceptions' do
exceptions = [ exceptions = Gitlab::HTTP::HTTP_ERRORS + [
SocketError, OpenSSL::SSL::SSLError, Errno::ECONNRESET, Errno::ECONNREFUSED, Gitlab::Json::LimitedEncoder::LimitExceeded, URI::InvalidURIError
Errno::EHOSTUNREACH, Net::OpenTimeout, Net::ReadTimeout,
Gitlab::HTTP::BlockedUrlError, Gitlab::HTTP::RedirectionTooDeep
] ]
exceptions.each do |exception_class| exceptions.each do |exception_class|
exception = exception_class.new('Exception message') exception = exception_class.new('Exception message')
project_hook.enable! project_hook.enable!
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment