Class: Response::Errors

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

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/faraday/errors.rb', line 7

def call(env)
  @app.call(env).on_complete do
    case env[:status]
      when 400
        raise FiveMobilePush::GeneralError, response_values(env)
      when 401
        raise FiveMobilePush::UnauthorizedError, response_values(env)
      when 500
        env[:body] = 'push.fivemobile.com is currently down'
        raise FiveMobilePush::ServerError, response_values(env)
    end
  end
end

#response_values(env) ⇒ Object

Copied from Faraday



22
23
24
# File 'lib/faraday/errors.rb', line 22

def response_values(env)
  { :status => env[:status], :headers => env[:response_headers], :body => env[:body] }
end