Skip to content

Commit 4356b85

Browse files
committed
Merge pull request #632 from vijoc/flatten-exception-class-whitelist
Flatten and check exception class whitelisting with a method
2 parents 0e45fd5 + 91f9830 commit 4356b85

3 files changed

Lines changed: 6 additions & 2 deletions

File tree

lib/jsonapi/acts_as_resource_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def handle_exceptions(e)
179179
when JSONAPI::Exceptions::Error
180180
render_errors(e.errors)
181181
else
182-
if JSONAPI.configuration.exception_class_whitelist.any? { |k| e.class.ancestors.include?(k) }
182+
if JSONAPI.configuration.exception_class_whitelisted?(e)
183183
fail e
184184
else
185185
internal_server_error = JSONAPI::Exceptions::InternalServerError.new(e)

lib/jsonapi/configuration.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ def operations_processor=(operations_processor)
9595
@operations_processor = JSONAPI::OperationsProcessor.operations_processor_for(@operations_processor_name)
9696
end
9797

98+
def exception_class_whitelisted?(e)
99+
@exception_class_whitelist.flatten.any? { |k| e.class.ancestors.include?(k) }
100+
end
101+
98102
attr_writer :allow_include, :allow_sort, :allow_filter
99103

100104
attr_writer :default_paginator

lib/jsonapi/operations_processor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def with_default_handling(&block)
9292
raise e
9393

9494
rescue => e
95-
if JSONAPI.configuration.exception_class_whitelist.any? { |k| e.class.ancestors.include?(k) }
95+
if JSONAPI.configuration.exception_class_whitelisted?(e)
9696
raise e
9797
else
9898
@request.server_error_callbacks.each { |callback| safe_run_callback(callback, e) }

0 commit comments

Comments
 (0)