Class: Telleroo::Response::RaiseClientError

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/telleroo/response/raise_client_error.rb

Overview

Handles API Response Errors

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/telleroo/response/raise_client_error.rb', line 8

def on_complete(env)
  status  = env[:status].to_i
  body    = env[:body]
  headers = env[:response_headers]

  case status
  when 401
    raise Telleroo::Error::Unauthorized.new body, headers
  when 406
    raise Telleroo::Error::NotAcceptable.new body, headers
  when 422
    raise Telleroo::Error::Unprocessable.new body, headers
  when 429
    raise Telleroo::Error::RateLimit.new body, headers
  end
end