Exception: Validic::Error

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

Constant Summary collapse

ClientError =
Class.new(self)
ServerError =
Class.new(self)
Unauthorized =
Class.new(ClientError)
NotFound =
Class.new(ClientError)
Forbidden =
Class.new(ClientError)
UnprocessableEntity =
Class.new(ClientError)
Conflict =
Class.new(ClientError)
InternalServerError =
Class.new(ServerError)
InvalidDate =
Class.new(ClientError)
ERRORS =
{
  401 => Validic::Error::Unauthorized,
  403 => Validic::Error::Forbidden,
  404 => Validic::Error::NotFound,
  406 => Validic::Error::InvalidDate,
  409 => Validic::Error::Conflict,
  422 => Validic::Error::UnprocessableEntity,
  500 => Validic::Error::InternalServerError
}

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message = '', code = nil) ⇒ Error

Returns a new instance of Error.



30
31
32
33
# File 'lib/validic/error.rb', line 30

def initialize(message = '', code = nil)
  super(message)
  @code = code
end

Class Method Details

.from_response(body) ⇒ Object



24
25
26
27
28
# File 'lib/validic/error.rb', line 24

def self.from_response(body)
  code, errors = [body['code'], body['errors']]
  message = "#{code}: #{errors}"
  new(message)
end