Class: Response::RaiseDatmachineError

Inherits:
Middleware
  • Object
show all
Defined in:
lib/datmachine/response/datmachine_exception_middleware.rb

Constant Summary collapse

HTTP_STATUS_CODES =
{
    300 => Datmachine::MoreInformationRequired,
    400 => Datmachine::BadRequest,
    401 => Datmachine::Unauthorized,
    402 => Datmachine::PaymentRequired,
    403 => Datmachine::Forbidden,
    404 => Datmachine::NotFound,
    405 => Datmachine::MethodNotAllowed,
    409 => Datmachine::Conflict,
    410 => Datmachine::Gone,
    500 => Datmachine::InternalServerError,
    501 => Datmachine::NotImplemented,
    502 => Datmachine::BadGateway,
    503 => Datmachine::ServiceUnavailable,
    504 => Datmachine::GatewayTimeout,
}

Instance Method Summary collapse

Instance Method Details

#on_complete(response) ⇒ Object

Raises:

  • (error_class)


26
27
28
29
30
# File 'lib/datmachine/response/datmachine_exception_middleware.rb', line 26

def on_complete(response)
  status_code = response[:status].to_i
  error_class = CATEGORY_CODE_MAP[category_code] || HTTP_STATUS_CODES[status_code]
  raise error_class.new(response) if error_class
end