Sha256: 3074e382ed9958a91873d02798222530eb12b04b0fb5ede5b5ea48d09c150113

Contents?: true

Size: 1.3 KB

Versions: 9

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

9 entries across 9 versions & 1 rubygems

Version Path
pact_broker-2.79.1 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.79.0 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.78.1 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.78.0 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.77.0 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.76.2 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.76.1 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.76.0 lib/pact_broker/api/resources/error_response_body_generator.rb
pact_broker-2.75.0 lib/pact_broker/api/resources/error_response_body_generator.rb