-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
I use the same pattern from this PR here: #1686 Looks like it's always better to pass `URI` instead of `string`: https://ruby-doc.org/stdlib-2.4.1/libdoc/net/http/rdoc/Net/HTTPGenericRequest.html Because `@uri` and `@host` get initialized.
- Loading branch information
1 parent
60dc5fc
commit 43e2833
Showing
3 changed files
with
40 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# frozen_string_literal: true | ||
|
||
module SignalAdapter | ||
class Api | ||
class << self | ||
def perform_request(request) | ||
uri = request.uri | ||
response = Net::HTTP.start(uri.host, uri.port) do |http| | ||
http.request(request) | ||
end | ||
case response | ||
when Net::HTTPSuccess | ||
yield response | ||
else | ||
error_message = JSON.parse(response.body)['error'] | ||
exception = SignalAdapter::BadRequestError.new(error_code: response.code, message: error_message) | ||
context = { | ||
code: response.code, | ||
message: response.message, | ||
headers: response.to_hash, | ||
body: error_message | ||
} | ||
ErrorNotifier.report(exception, context: context) | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters