Class: Response::RaiseError

Inherits:
Middleware
  • Object
show all
Defined in:
lib/faraday/response/raise_error.rb,
lib/faraday/raise_error.rb

Instance Method Summary collapse

Instance Method Details

#error_message(response) ⇒ Object



27
28
29
# File 'lib/faraday/response/raise_error.rb', line 27

def error_message(response)
  "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:response_headers]['status']}#{(': ' + response[:body]['error']) if response[:body] && response[:body]['error']}"
end

#on_complete(response) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/faraday/response/raise_error.rb', line 6

def on_complete(response)
  case response[:status].to_i
  when 400
    raise SBA::BadRequest, error_message(response)
  when 401
    raise SBA::Unauthorized, error_message(response)
  when 403
    raise SBA::Forbidden, error_message(response)
  when 404
    raise SBA::NotFound, error_message(response)
  when 406
    raise SBA::NotAcceptable, error_message(response)
  when 500
    raise SBA::InternalServerError, error_message(response)
  when 502
    raise SBA::BadGateway, error_message(response)
  when 503
    raise SBA::ServiceUnavailable, error_message(response)
  end
end