Exception: Billogram::Error

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

Defined Under Namespace

Classes: BadRequest, Forbidden, InternalServerError, NotFound, Unauthorized

Class Method Summary collapse

Class Method Details

.from_response(response) ⇒ Object



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

def self.from_response(response)
  status  = response.response.code.to_i
  body    = response.body.to_s
  headers = response.headers
  message = error_message(response)

  if klass =  case status
              when 400      then BadRequest
              when 401      then Unauthorized
              when 403      then Forbidden
              when 404      then NotFound
              when 500      then InternalServerError
              else               Billogram::Error
              end
    klass.new(message)
  end
end