Class: Response::RaiseReadmillError
- Inherits:
-
Middleware
- Object
- Middleware
- Response::RaiseReadmillError
- Defined in:
- lib/faraday/response/raise_readmill_error.rb
Overview
Instance Method Summary collapse
-
#error_message(response) ⇒ Object
Internal: Parse the response and return a human friendly String representing the error that we received.
-
#on_complete(response) ⇒ Object
Internal: Hook into the complete callback for the client.
Instance Method Details
#error_message(response) ⇒ Object
Internal: Parse the response and return a human friendly String representing the error that we received.
Returns a String.
44 45 46 47 48 49 50 |
# File 'lib/faraday/response/raise_readmill_error.rb', line 44 def (response) method = response[:method].to_s.upcase url = response[:url].to_s status = response[:body][:status] error = response[:body][:error] "#{method} #{url}: #{status} - #{error}" end |
#on_complete(response) ⇒ Object
Internal: Hook into the complete callback for the client. When the result comes back, if it is a status code that we want to raise an error for, we will do that.
Returns nothing.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/faraday/response/raise_readmill_error.rb', line 21 def on_complete(response) return if response[:body].nil? case response[:body][:status].to_i when 400 raise Readmill::BadRequest, (response) when 401 raise Readmill::Unauthorized, (response) when 403 raise Readmill::Forbidden, (response) when 404 raise Readmill::NotFound, (response) when 500 raise Readmill::InternalServerError, (response) when 504 raise Readmill::GatewayTimeout, (response) end end |