Class: Desk::Response::ErrorHandling

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/desk/response/error_handling.rb

Constant Summary collapse

ERROR_TYPE =
{
  400 => BadRequest,
  401 => Unauthorized,
  404 => NotFound,
  403 => Forbidden,
  405 => MethodNotAllowed,
  406 => NotAcceptable,
  409 => Conflict,
  415 => UnsupportedMediaType,
  422 => UnprocessableEntity,
  429 => TooManyRequests,
  501 => NotImplemented
}

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/desk/response/error_handling.rb', line 21

def call(env)
  @app.call(env).on_complete do |finished_env|
    if finished_env[:status] >= 400
      raise ERROR_TYPE[finished_env[:status]], finished_env[:body]["message"] if ERROR_TYPE[finished_env[:status]]
    end
  end
end