Class: Response::RaiseHttp4xx

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RaiseHttp4xx

Returns a new instance of RaiseHttp4xx.



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

def initialize(app)
  super
  @parser = nil
end

Class Method Details

.register_on_complete(env) ⇒ Object



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

def self.register_on_complete(env)
  env[:response].on_complete do |response|
    case response[:status].to_i
      when 400
        raise BullionVault::BadRequest, error_message(response)
      when 401
        raise BullionVault::Unauthorized, error_message(response)
      when 403
        raise BullionVault::Forbidden, error_message(response)
      when 404
        raise BullionVault::NotFound, error_message(response)
      when 406
        raise BullionVault::NotAcceptable, error_message(response)
    end
  end
end