Class: FaradayMiddleware::RaiseHttpException

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/adriver_api/raise_http_exception.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RaiseHttpException

Returns a new instance of RaiseHttpException.



19
20
21
22
# File 'lib/adriver_api/raise_http_exception.rb', line 19

def initialize(app)
  super app
  @parser = nil
end

Instance Method Details

#call(env) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/adriver_api/raise_http_exception.rb', line 5

def call(env)
  @app.call(env).on_complete do |response|
    case response[:status].to_i
    when 400
      raise AdriverApi::BadRequest
    when 401
      raise AdriverApi::AccessDenied if response.body.include? 'Not authorized to work with object'
      raise AdriverApi::UnAuthorized
    when 404
      raise AdriverApi::NotFound
    end
  end
end