Exception: Monokera::SDK::Error

Inherits:
StandardError
  • Object
show all
Defined in:
lib/monokera/sdk/error.rb

Defined Under Namespace

Classes: Middleware

Constant Summary collapse

ClientError =
Class.new(self)
BadRequest =
Class.new(ClientError)
NotFound =
Class.new(ClientError)
Conflict =
Class.new(ClientError)
Gone =
Class.new(ClientError)
UnprocessableEntity =
Class.new(ClientError)
ServerError =
Class.new(self)
InternalServerError =
Class.new(ServerError)
ServiceUnavailableError =
Class.new(ServerError)
HTTP_ERRORS =
{
  400 => BadRequest,
  401 => ClientError,
  404 => NotFound,
  409 => Conflict,
  410 => Gone,
  422 => UnprocessableEntity,
  500 => InternalServerError,
  503 => ServiceUnavailableError
}.freeze
ERROR_STATUSES =
[400, 600].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Error

Returns a new instance of Error.



55
56
57
58
# File 'lib/monokera/sdk/error.rb', line 55

def initialize(env)
  super(env)
  @env = env
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



53
54
55
# File 'lib/monokera/sdk/error.rb', line 53

def env
  @env
end

Class Method Details

.raise_if_http_error!(status, env) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/monokera/sdk/error.rb', line 45

def self.raise_if_http_error!(status, env)
  if status.between?(*ERROR_STATUSES)
    error_klass = HTTP_ERRORS.fetch(status, Error)

    raise error_klass, env
  end
end