Exception: Housecanary::Error

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

Overview

:nodoc:

Constant Summary collapse

NoContent =
Class.new(self)
BadRequest =
Class.new(self)
Unauthorized =
Class.new(self)
Forbidden =
Class.new(self)
NotFound =
Class.new(self)
InternalServerError =
Class.new(self)
TooManyRequests =
Class.new(self)
ERRORS_MAP =
{
  204 => Housecanary::Error::NoContent,
  400 => Housecanary::Error::BadRequest,
  401 => Housecanary::Error::Unauthorized,
  403 => Housecanary::Error::Forbidden,
  404 => Housecanary::Error::NotFound,
  429 => Housecanary::Error::TooManyRequests,
  500 => Housecanary::Error::InternalServerError
}.freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



5
6
7
# File 'lib/housecanary/error.rb', line 5

def code
  @code
end

Class Method Details

.from_response(body) ⇒ Object



26
27
28
29
# File 'lib/housecanary/error.rb', line 26

def from_response(body)
  message, status = parse_error(body)
  new(message, status)
end

.parse_error(body) ⇒ Object



31
32
33
34
35
# File 'lib/housecanary/error.rb', line 31

def parse_error(body)
  message = body.fetch(:message, nil) || body.fetch(:api_code_description, nil)
  status = body.fetch(:status, nil) || body.fetch(:api_code, nil)
  [message, status]
end