Class: Twitter::Response::RaiseClientError

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

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/twitter/response/raise_client_error.rb', line 13

def on_complete(env)
  case env[:status].to_i
  when 400
    raise Twitter::Error::BadRequest.new(error_body(env[:body]), env[:response_headers])
  when 401
    raise Twitter::Error::Unauthorized.new(error_body(env[:body]), env[:response_headers])
  when 403
    raise Twitter::Error::Forbidden.new(error_body(env[:body]), env[:response_headers])
  when 404
    raise Twitter::Error::NotFound.new(error_body(env[:body]), env[:response_headers])
  when 406
    raise Twitter::Error::NotAcceptable.new(error_body(env[:body]), env[:response_headers])
  when 420
    raise Twitter::Error::EnhanceYourCalm.new(error_body(env[:body]), env[:response_headers])
  end
end