Skip to content

Commit

Permalink
fix: add missing info level log for business level errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Aug 4, 2020
1 parent 76c6e3a commit 80a895b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/pact_broker/api/resources/error_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module PactBroker
module Api
module Resources
class ErrorHandler

include PactBroker::Logging

WARNING_ERROR_CLASSES = [Sequel::ForeignKeyConstraintViolation]
Expand All @@ -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
Expand Down
19 changes: 18 additions & 1 deletion spec/lib/pact_broker/api/resources/error_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 80a895b

Please sign in to comment.