Class: FabricCA::FaradayMiddleware::RaiseHttpException

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, logger) ⇒ RaiseHttpException

Returns a new instance of RaiseHttpException.



21
22
23
24
# File 'lib/fabric_ca/faraday_middleware/raise_http_exception.rb', line 21

def initialize(app, logger)
  @app = app
  @logger = logger
end

Instance Attribute Details

#appObject (readonly)

Attributes



7
8
9
# File 'lib/fabric_ca/faraday_middleware/raise_http_exception.rb', line 7

def app
  @app
end

#loggerObject (readonly)

Attributes



7
8
9
# File 'lib/fabric_ca/faraday_middleware/raise_http_exception.rb', line 7

def logger
  @logger
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/fabric_ca/faraday_middleware/raise_http_exception.rb', line 9

def call(env)
  app.call(env).on_complete do |response|
    case response[:status].to_i
    when 400..504
      message = build_error_message response
      logging message

      raise FabricCA::Error.new message, response
    end
  end
end