Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/jsonapi/acts_as_resource_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ def handle_exceptions(e)
}
end

# Store exception for other middlewares
request.env['action_dispatch.exception'] ||= e

internal_server_error = JSONAPI::Exceptions::InternalServerError.new(e)
Rails.logger.error { "Internal Server Error: #{e.message} #{e.backtrace.join("\n")}" }
errors = internal_server_error.errors
Expand Down
15 changes: 15 additions & 0 deletions test/controllers/controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,21 @@ def test_whitelist_all_exceptions
JSONAPI.configuration.whitelist_all_exceptions = original_config
end

def test_exception_added_to_request_env
original_config = JSONAPI.configuration.whitelist_all_exceptions
$PostProcessorRaisesErrors = true
refute @request.env['action_dispatch.exception']
assert_cacheable_get :index
assert @request.env['action_dispatch.exception']

JSONAPI.configuration.whitelist_all_exceptions = true
assert_cacheable_get :index
assert @request.env['action_dispatch.exception']
ensure
$PostProcessorRaisesErrors = false
JSONAPI.configuration.whitelist_all_exceptions = original_config
end

def test_exception_includes_backtrace_when_enabled
original_config = JSONAPI.configuration.include_backtraces_in_errors
$PostProcessorRaisesErrors = true
Expand Down