Class: Pact::Consumer::MockService::ErrorHandler
- Inherits:
-
Object
- Object
- Pact::Consumer::MockService::ErrorHandler
- Defined in:
- lib/pact/consumer/mock_service/error_handler.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, logger) ⇒ ErrorHandler
constructor
A new instance of ErrorHandler.
- #shutdown ⇒ Object
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. [500, {'Content-Type' => 'application/json'}, [{message: e.}.to_json]] rescue StandardError => e = "Error ocurred in mock service: #{e.class} - #{e.}" @logger.error @logger.error e.backtrace.join("\n") [500, {'Content-Type' => 'application/json'}, [{message: , backtrace: e.backtrace}.to_json]] end end |
#shutdown ⇒ Object
25 26 27 |
# File 'lib/pact/consumer/mock_service/error_handler.rb', line 25 def shutdown @app.shutdown end |