Class: RestfulResourceBugsnag::Middleware
- Inherits:
-
Object
- Object
- RestfulResourceBugsnag::Middleware
- Defined in:
- lib/restful_resource_bugsnag/middleware.rb
Instance Method Summary collapse
- #call(notification) ⇒ Object
-
#initialize(bugsnag) ⇒ Middleware
constructor
A new instance of Middleware.
Constructor Details
#initialize(bugsnag) ⇒ Middleware
Returns a new instance of Middleware.
5 6 7 |
# File 'lib/restful_resource_bugsnag/middleware.rb', line 5 def initialize(bugsnag) @bugsnag = bugsnag end |
Instance Method Details
#call(notification) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/restful_resource_bugsnag/middleware.rb', line 9 def call(notification) exception = notification.raw_exceptions.first if exception.is_a?(RestfulResource::HttpClient::HttpError) notification.( :restful_resource_response, { status: exception.response.status, body: attempt_json_parse(exception.response.body), headers: exception.response.headers } ) notification.( :restful_resource_request, { method: exception.request.method, url: exception.request.url, body: attempt_json_parse(exception.request.body) } ) end # Display the request host in the context so its easy to see in Bugsnag which service was unresponsive # Group the errors by host to reduce the amount of error spam if exception.is_a?(RestfulResource::HttpClient::ServiceUnavailable) notification.context = "HTTP 503: Service unavailable #{request_host_from_exception exception}" notification.grouping_hash = notification.context end if exception.is_a?(RestfulResource::HttpClient::ClientError) notification.context = "Client error: Service unavailable #{request_host_from_exception exception}" notification.grouping_hash = notification.context end if exception.is_a?(RestfulResource::HttpClient::Timeout) notification.context = "Client error: Timeout #{request_host_from_exception exception}" notification.grouping_hash = notification.context end @bugsnag.call(notification) end |