Skip to content

Commit

Permalink
chore: allow warning level errors to be configured
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Aug 6, 2020
1 parent 80a895b commit 4f18452
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 1 addition & 3 deletions lib/pact_broker/api/resources/error_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ module Resources
class ErrorHandler
include PactBroker::Logging

WARNING_ERROR_CLASSES = [Sequel::ForeignKeyConstraintViolation]

def self.call e, request, response
error_reference = generate_error_reference
if log_as_warning?(e)
Expand All @@ -31,7 +29,7 @@ def self.reportable?(e)
end

def self.log_as_warning?(e)
WARNING_ERROR_CLASSES.any? { |clazz| e.is_a?(clazz) }
PactBroker.configuration.warning_error_classes.any? { |clazz| e.is_a?(clazz) }
end

def self.display_message(e, error_reference)
Expand Down
11 changes: 10 additions & 1 deletion lib/pact_broker/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ class Configuration
:webhook_host_whitelist,
:base_equality_only_on_content_that_affects_verification_results,
:seed_example_data,
:badge_provider_mode
:badge_provider_mode,
:warning_error_class_names
]

attr_accessor :base_url, :log_dir, :database_connection, :auto_migrate_db, :auto_migrate_db_data, :allow_missing_migration_files, :example_data_seeder, :seed_example_data, :use_hal_browser, :html_pact_renderer, :use_rack_protection
attr_accessor :validate_database_connection_config, :enable_diagnostic_endpoints, :version_parser, :sha_generator
attr_accessor :use_case_sensitive_resource_names, :order_versions_by_date
attr_accessor :warning_error_class_names
attr_accessor :check_for_potential_duplicate_pacticipant_names
attr_accessor :webhook_retry_schedule
attr_reader :webhook_http_method_whitelist, :webhook_scheme_whitelist, :webhook_host_whitelist
Expand Down Expand Up @@ -115,6 +117,7 @@ def self.default_configuration
require 'pact_broker/api/resources/default_base_resource'
PactBroker::Api::Resources::DefaultBaseResource
}
config.warning_error_class_names = ['Sequel::ForeignKeyConstraintViolation']
config
end

Expand Down Expand Up @@ -228,6 +231,12 @@ def webhook_host_whitelist= webhook_host_whitelist
@webhook_host_whitelist = parse_space_delimited_string_list_property('webhook_host_whitelist', webhook_host_whitelist)
end

def warning_error_classes
warning_error_class_names.collect do | class_name |
Object.const_get(class_name)
end
end

private

def parse_space_delimited_string_list_property property_name, property_value
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/pact_broker/api/resources/error_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module Resources
subject
end

context "when the error class is in the WARNING_ERROR_CLASSES list" do
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
Expand Down

0 comments on commit 4f18452

Please sign in to comment.