Class: UplandMobileCommonsRest::HttpErrorMiddleware
- Inherits:
-
Faraday::Response::Middleware
- Object
- Faraday::Response::Middleware
- UplandMobileCommonsRest::HttpErrorMiddleware
- Defined in:
- lib/upland_mobile_commons_rest/errors.rb
Overview
This middleware runs before XML parsing, so we can include the raw response body in the exception.
Instance Method Summary collapse
Instance Method Details
#on_complete(response) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/upland_mobile_commons_rest/errors.rb', line 27 def on_complete(response) status_code = response[:status].to_i # Raise an exception for 5xx errors. # Q: Shouldn't we also raise for 4xx errors? # A: We let TypedErrorMiddleware handle those, in case they have useful info. case status_code when 502 raise BadGatewayError.new(response) when 504 raise GatewayTimeoutError.new(response) when 500...600 # Just in case we get other 5xx errors, raise something for those # This has not happened that we know of, but better safe than sorry! raise UnknownError, response.inspect end end |