Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special error to distinguish broken connection #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/send_sonar/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,15 @@ def self.post(url, payload, headers={}, &block)
rescue RestClient::Exception => e
if e.http_code == 400
raise BadRequest.new(e)
elsif e.to_s.match(/Server broke connection/)
raise ServerBrokeConnection.new(e)
else
response = e.response && JSON.parse(e.response) || {}
error = response["error"]
begin
response = e.response && JSON.parse(e.response) || {}
error = response["error"]
rescue JSON::ParserError
error = e.response
end
exception_class = Exceptions::EXCEPTIONS_MAP[error] || UnknownRequestError
raise exception_class.new(e)
end
Expand Down
1 change: 1 addition & 0 deletions lib/send_sonar/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class NoActiveSubscription < RequestException; end
class ApiDisabledForCompany < RequestException; end
class UnknownRequestError < RequestException; end
class RequestTimeout < RequestException; end
class ServerBrokeConnection < RequestException; end
class ConnectionRefused < RequestException; end

class Customer < OpenStruct; end
Expand Down