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 Tweetsentiments::BadRequest, error_message(response)
    when 401
      raise Tweetsentiments::Unauthorized, error_message(response)
    when 403
      raise Tweetsentiments::Forbidden, error_message(response)
    when 404
      raise Tweetsentiments::NotFound, error_message(response)
    when 406
      raise Tweetsentiments::NotAcceptable, error_message(response)
    when 420
      raise Tweetsentiments::RateLimited, error_message(response)
    end
  end
end