Class: Response::RaiseGuidestarError

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

Instance Method Summary collapse

Instance Method Details

#error_message(response) ⇒ Object



33
34
35
# File 'lib/faraday/response/raise_guidestar_error.rb', line 33

def error_message(response)
  "#{response[:description]}\n#{response[:body]}"
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
26
27
28
29
30
31
# File 'lib/faraday/response/raise_guidestar_error.rb', line 6

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