diff --git a/lib/pact_broker/api/resources/error_handler.rb b/lib/pact_broker/api/resources/error_handler.rb index 9a83721d8..3947b1f9c 100644 --- a/lib/pact_broker/api/resources/error_handler.rb +++ b/lib/pact_broker/api/resources/error_handler.rb @@ -5,7 +5,6 @@ module PactBroker module Api module Resources class ErrorHandler - include PactBroker::Logging WARNING_ERROR_CLASSES = [Sequel::ForeignKeyConstraintViolation] @@ -17,6 +16,7 @@ def self.call e, request, response elsif reportable?(e) log_error(e, "Error reference #{error_reference}") report(e, error_reference, request) + else logger.info("Error reference #{error_reference}", e) end response.body = response_body_hash(e, error_reference).to_json diff --git a/spec/lib/pact_broker/api/resources/error_handler_spec.rb b/spec/lib/pact_broker/api/resources/error_handler_spec.rb index aa83f5d7f..2203a840c 100644 --- a/spec/lib/pact_broker/api/resources/error_handler_spec.rb +++ b/spec/lib/pact_broker/api/resources/error_handler_spec.rb @@ -5,7 +5,6 @@ module Api module Resources describe ErrorHandler do describe "call" do - before do allow(ErrorHandler).to receive(:logger).and_return(logger) allow(SecureRandom).to receive(:urlsafe_base64).and_return("bYWfn-+yWPlf") @@ -45,6 +44,24 @@ module Resources subject end + context "when the error class is in the WARNING_ERROR_CLASSES list" do + let(:error) { Sequel::ForeignKeyConstraintViolation.new } + + it "logs at warn so as not to wake everyone up in the middle of the night" do + expect(logger).to receive(:warn).with(/bYWfnyWPlf/, error) + subject + end + end + + context "when the error is not reportable and not a warning level" do + let(:error) { PactBroker::Error.new('foo') } + + it "logs at info" do + expect(logger).to receive(:info).with(/bYWfnyWPlf/, error) + subject + end + end + context "when show_backtrace_in_error_response? is true" do before do allow(PactBroker.configuration).to receive(:show_backtrace_in_error_response?).and_return(true)