Sha256: 7116262298f5babd9f574f94316b53234805921ed3e51bf9af198cb484dee5db

Contents?: true

Size: 1.3 KB

Versions: 35

Compression:

Stored size: 1.3 KB

Contents

require "pact_broker/configuration"

module PactBroker
  module Api
    module Resources
      class ErrorResponseBodyGenerator
        include PactBroker::Logging

        # env not needed, just passing in in case PF ever needs it
        def self.call error, error_reference, _env = {}
          response_body_hash(error, error_reference).to_json
        end

        def self.display_message(error, obfuscated_message)
          if PactBroker.configuration.show_backtrace_in_error_response?
            error.message || obfuscated_message
          else
            PactBroker::Errors.reportable_error?(error) ? obfuscated_message : error.message
          end
        end

        def self.obfuscated_error_message(error_reference)
          "An error has occurred. The details have been logged with the reference #{error_reference}"
        end

        def self.response_body_hash(error, error_reference)
          response_body = {
            error: {
              message: display_message(error, obfuscated_error_message(error_reference)),
              reference: error_reference
            }
          }
          if PactBroker.configuration.show_backtrace_in_error_response?
            response_body[:error][:backtrace] = error.backtrace
          end
          response_body
        end
      end
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
pact_broker-2.105.0 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.104.0 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.103.0 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.102.2 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.102.1 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.102.0 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.101.0 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.100.0 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.99.0 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.98.0 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.97.0 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.96.0 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.95.1 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.95.0 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.94.0 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.93.4 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.93.3 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.93.2 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.93.1 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.93.0 lib/pact_broker/api/resources/error_response_body_generator.rb