Class: Footrest::RaiseFootrestErrors

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/footrest/http_error.rb

Constant Summary collapse

ERROR_MAP =
{
  400 => Footrest::HttpError::BadRequest,
  401 => Footrest::HttpError::Unauthorized,
  403 => Footrest::HttpError::Forbidden,
  404 => Footrest::HttpError::NotFound,
  405 => Footrest::HttpError::MethodNotAllowed,
  500 => Footrest::HttpError::InternalServerError,
  501 => Footrest::HttpError::NotImplemented,
  502 => Footrest::HttpError::BadGateway,
  503 => Footrest::HttpError::ServiceUnavailable
}

Instance Method Summary collapse

Instance Method Details

#on_complete(response) ⇒ Object

Raises:


85
86
87
88
# File 'lib/footrest/http_error.rb', line 85

def on_complete(response)
  key = response[:status].to_i
  raise ERROR_MAP[key].new(response) if ERROR_MAP.has_key? key
end