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.



26
27
28
29
# File 'lib/faraday/raise_http_4xx.rb', line 26

def initialize(app)
  super
  @parser = nil
end

Class Method Details

.register_on_complete(env) ⇒ Object



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

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