Module: Tito::Errors

Defined in:
lib/tito/errors.rb

Defined Under Namespace

Classes: ApiError, ConfigurationError, Error, ForbiddenError, NotFoundError, RateLimitError, ServerError, UnauthorizedError, ValidationError

Constant Summary collapse

MAPPING =
{
  401 => UnauthorizedError,
  403 => ForbiddenError,
  404 => NotFoundError,
  422 => ValidationError,
  429 => RateLimitError
}.freeze

Class Method Summary collapse

Class Method Details

.from_response(response) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/tito/errors.rb', line 32

def self.from_response(response)
  status = response.status
  body = response.body

  klass = MAPPING[status] || (status >= 500 ? ServerError : ApiError)
  klass.new(status: status, body: body)
end