Sha256: 39be00445cbec511dbe2dd1ce89816f2721c2f94841244553fad16e7fd6b0c95

Contents?: true

Size: 1.11 KB

Versions: 4

Compression:

Stored size: 1.11 KB

Contents

require 'webmachine/convert_request_to_rack_env'
require 'pact_broker/configuration'

module PactBroker
  module Api
    module Resources
      class ErrorHandler

        include PactBroker::Logging
        include PactBroker::Logging

        def self.call e, request, response
          logger.error e
          logger.error e.backtrace
          response_body = { error: { :message => e.message } }
          if PactBroker.configuration.show_backtrace_in_error_response?
            response_body[:error][:backtrace] = e.backtrace
          end
          response.body = response_body.to_json
          report(e, request) if reportable?(e)
        end

        def self.reportable? e
          !e.is_a?(PactBroker::Error)
        end

        def self.report e, request
          PactBroker.configuration.api_error_reporters.each do | error_notifier |
            begin
              error_notifier.call(e, env: Webmachine::ConvertRequestToRackEnv.call(request))
            rescue StandardError => e
              log_error(e, "Error executing api_error_reporter")
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pact_broker-2.27.6 lib/pact_broker/api/resources/error_handler.rb
pact_broker-2.27.5 lib/pact_broker/api/resources/error_handler.rb
pact_broker-2.27.4 lib/pact_broker/api/resources/error_handler.rb
pact_broker-2.27.3 lib/pact_broker/api/resources/error_handler.rb