Class: Response::FullContactErrors

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ FullContactErrors

Returns a new instance of FullContactErrors.



31
32
33
34
# File 'lib/faraday/response/fullcontact_errors.rb', line 31

def initialize(app)
  super
  @parser = nil
end

Instance Method Details

#error_message(env) ⇒ Object



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

def error_message(env)
  "#{env[:method].to_s.upcase} #{env[:url].to_s}: #{env[:status]}"
end

#on_complete(env) ⇒ Object



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

def on_complete(env)
  case env[:status]
    when 400
      raise FullContact::BadRequest.new(error_message(env), env[:response_headers])
    when 401
      raise FullContact::Unauthorized.new(error_message(env), env[:response_headers])
    when 403
      raise FullContact::Forbidden.new(error_message(env), env[:response_headers])
    when 404
      raise FullContact::NotFound.new(error_message(env), env[:response_headers])
    when 422
      raise FullContact::Invalid.new(error_message(env), env[:response_headers])
    when 429
      # Note: not currently in use
      raise FullContact::RateLimited.new(error_message(env), env[:response_headers])
    when 500
      raise FullContact::InternalServerError.new(error_message(env), env[:response_headers])
    when 502
      raise FullContact::BadGateway.new(error_message(env), env[:response_headers])
    when 503
      raise FullContact::ServiceUnavailable.new(error_message(env), env[:response_headers])
  end
end