Class: Open311::Response::RaiseError Private

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

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Instance Method Details

#error_message(response) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



28
29
30
# File 'lib/open311/response/raise_error.rb', line 28

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

#on_complete(response) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

rubocop:disable AbcSize, CyclomaticComplexity, MethodLength



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

def on_complete(response) # rubocop:disable AbcSize, CyclomaticComplexity, MethodLength
  case response[:status].to_i
  when 400
    fail Open311::BadRequest.new(error_message(response))
  when 401
    fail Open311::Unauthorized.new(error_message(response))
  when 403
    fail Open311::Forbidden.new(error_message(response))
  when 404
    fail Open311::NotFound.new(error_message(response))
  when 406
    fail Open311::NotAcceptable.new(error_message(response))
  when 500
    fail Open311::InternalServerError.new(error_message(response))
  when 502
    fail Open311::BadGateway.new(error_message(response))
  when 503
    fail Open311::ServiceUnavailable.new(error_message(response))
  end
end