diff options
author | Peter Leitzen <pleitzen@gitlab.com> | 2019-04-07 07:51:36 +0000 |
---|---|---|
committer | Michael Kozono <mkozono@gmail.com> | 2019-04-07 07:51:36 +0000 |
commit | bbb17ea1ea619664b362a9c984da45b940c412a2 (patch) | |
tree | 617df6d7bd4186c7f1eec0374e975375323d20b9 /lib | |
parent | ae91b3219aa0b5de20e3452126384341acef75c6 (diff) | |
download | gitlab-ce-bbb17ea1ea619664b362a9c984da45b940c412a2.tar.gz |
Handle possible HTTP exception for Sentry client
Prior this commit exceptions raised during a HTTP request
weren't caught by the Sentry client and were passed to the user.
In addition the Sentry client tried to catch a non-existent error
`Sentry::Client::SentryError`.
Now, the Sentry client catches all possible errors coming from
a HTTP request.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/sentry/client.rb | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/lib/sentry/client.rb b/lib/sentry/client.rb index bb1aa2a7a10..4022e8ff946 100644 --- a/lib/sentry/client.rb +++ b/lib/sentry/client.rb @@ -47,9 +47,11 @@ module Sentry end def http_get(url, params = {}) - resp = Gitlab::HTTP.get(url, **request_params.merge(params)) + response = handle_request_exceptions do + Gitlab::HTTP.get(url, **request_params.merge(params)) + end - handle_response(resp) + handle_response(response) end def get_issues(issue_status:, limit:) @@ -63,14 +65,36 @@ module Sentry http_get(projects_api_url) end + def handle_request_exceptions + yield + rescue HTTParty::Error => e + Gitlab::Sentry.track_acceptable_exception(e) + raise_error 'Error when connecting to Sentry' + rescue Net::OpenTimeout + raise_error 'Connection to Sentry timed out' + rescue SocketError + raise_error 'Received SocketError when trying to connect to Sentry' + rescue OpenSSL::SSL::SSLError + raise_error 'Sentry returned invalid SSL data' + rescue Errno::ECONNREFUSED + raise_error 'Connection refused' + rescue => e + Gitlab::Sentry.track_acceptable_exception(e) + raise_error "Sentry request failed due to #{e.class}" + end + def handle_response(response) unless response.code == 200 - raise Client::Error, "Sentry response status code: #{response.code}" + raise_error "Sentry response status code: #{response.code}" end response end + def raise_error(message) + raise Client::Error, message + end + def projects_api_url projects_url = URI(@url) projects_url.path = '/api/0/projects/' |