Module: Easybill::Api::ResponseHandler::ClassMethods

Defined in:
lib/easybill/api/response_handler.rb

Instance Method Summary collapse

Instance Method Details

#handle(response) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/easybill/api/response_handler.rb', line 9

def handle(response)
  case response.code
  when 200..299
    response
  when 400
    raise Easybill::Errors::BadRequestError, response.body
  when 401
    raise Easybill::Errors::NotAuthorizedError, response.body
  when 404
    raise Easybill::Errors::ResourceNotFoundError, response.body
  when 429
    raise Easybill::Errors::RateLimitExceededError, response.body
  when 500...600
    raise Easybill::Errors::ServerError, "Failed with: #{response.code} #{response.body}"
  end
end