Class: Pact::Consumer::MockService::ErrorHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/pact/consumer/mock_service/error_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, logger) ⇒ ErrorHandler

Returns a new instance of ErrorHandler.



6
7
8
9
# File 'lib/pact/consumer/mock_service/error_handler.rb', line 6

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

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pact/consumer/mock_service/error_handler.rb', line 11

def call env
  begin
    @app.call(env)
  rescue Pact::Error => e
    @logger.error e.message
    [500, {'Content-Type' => 'application/json'}, [{message: e.message}.to_json]]
  rescue StandardError => e
    message = "Error ocurred in mock service: #{e.class} - #{e.message}"
    @logger.error message
    @logger.error e.backtrace.join("\n")
    [500, {'Content-Type' => 'application/json'}, [{message: message, backtrace: e.backtrace}.to_json]]
  end
end

#shutdownObject



25
26
27
# File 'lib/pact/consumer/mock_service/error_handler.rb', line 25

def shutdown
  @app.shutdown
end