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

.error_class(response) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/billogram/error.rb', line 17

def error_class(response)
  case response.code.to_i
  when 400 then BadRequest
  when 401 then Unauthorized
  when 403 then Forbidden
  when 404 then NotFound
  when 500 then InternalServerError
  else Billogram::Error
  end
end

.from_response(response) ⇒ Object



12
13
14
15
# File 'lib/billogram/error.rb', line 12

def from_response(response)
  message = response.dig('data', 'message')
  error_class(response).new(message)
end