Class: MagicWrite::ErrorHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/magicwrite/error_handler.rb

Constant Summary collapse

HTTP_CODE =
{
  400 => MagicWrite::Error::BadRequest,
  401 => MagicWrite::Error::Unauthorized,
  402 => MagicWrite::Error::PaymentRequired,
  403 => MagicWrite::Error::Forbidden,
  404 => MagicWrite::Error::NotFound,
  405 => MagicWrite::Error::MethodNotAllowed,
  408 => MagicWrite::Error::RequestTimeout,
  409 => MagicWrite::Error::Conflict,
  422 => MagicWrite::Error::UnprocessableEntity,
  429 => MagicWrite::Error::TooManyRequests,
  500 => MagicWrite::Error::InternalServerError,
  501 => MagicWrite::Error::NotImplemented,
  502 => MagicWrite::Error::BadGateway,
  503 => MagicWrite::Error::ServiceUnavailable,
  504 => MagicWrite::Error::GatewayTimeout
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ErrorHandler

Returns a new instance of ErrorHandler.



21
22
23
24
# File 'lib/magicwrite/error_handler.rb', line 21

def initialize(response)
  @response = response
  @status = response.status
end

Instance Method Details

#raise_errorObject

Raises:

  • (error_class)


26
27
28
# File 'lib/magicwrite/error_handler.rb', line 26

def raise_error
  raise error_class, response.reason_phrase
end