Exception: Lotr::Error

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

Direct Known Subclasses

ClientError, ServerError

Class Method Summary collapse

Class Method Details

.from_response(response) ⇒ Lotr::Error

Returns the appropriate Lotr::Error subclass based on status and response message

Parameters:

  • response (Hash)

    HTTP response

Returns:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/lotr/error.rb', line 10

def self.from_response(response)
  status = response.code
  klass = case status
          when 400      then Lotr::BadRequest
          when 401      then Lotr::Unauthorized
          when 403      then Lotr::Forbidden
          when 404      then Lotr::NotFound
          when 422      then Lotr::UnprocessableEntity
          when 429      then Lotr::TooManyRequests
          when 400..499 then Lotr::ClientError
          when 500      then Lotr::InternalServerError
          when 501      then Lotr::NotImplemented
          when 502      then Lotr::BadGateway
          when 503      then Lotr::ServiceUnavailable
          when 500..599 then Lotr::ServerError
          end
  klass.new(response.message)
end