Class: Response::RaiseESPNError
- Inherits:
-
Middleware
- Object
- Middleware
- Response::RaiseESPNError
- Defined in:
- lib/faraday/response/raise_espn_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.
45 46 47 |
# File 'lib/faraday/response/raise_espn_error.rb', line 45 def (response) "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:body][:status]} - #{response[:body][:message]}" 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.
Raises ESPN::Unauthorized, ESPN::Forbidden and ESPN::Notfound. Returns nothing.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/faraday/response/raise_espn_error.rb', line 22 def on_complete(response) return if response[:body].nil? case response[:body][:code].to_i when 400 raise ESPN::BadRequest, (response) when 401 raise ESPN::Unauthorized, (response) when 403 raise ESPN::Forbidden, (response) when 404 raise ESPN::NotFound, (response) when 500 raise ESPN::InternalServerError, (response) when 504 raise ESPN::GatewayTimeout, (response) end end |