Class: Flattr::Response::RaiseClientError

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

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object



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

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