]> git.openstreetmap.org Git - rails.git/commit
Stop catching unanticipated exceptions in API calls
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 25 Nov 2026 14:16:50 +0000 (14:16 +0000)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 25 Nov 2026 16:23:57 +0000 (16:23 +0000)
commitb5c9314f2a08aa27eb8e4ce409132f2cd7209e95
tree62f65e398b3e49e3fceffb86c36c8543d6a9eb1f
parenta1752c3294ddf3ed88d3c90ac17772c0eb376cda
Stop catching unanticipated exceptions in API calls

api_call_handle_error rescued any unexpected exceptions and returned their
class and message to the client as 500 responses. The message can contain
internal details, such as SQL from database errors, that shouldn't be
shared with clients.

Additionally, catching these exceptions meant they were only written to
the logs, and the exception never reached Sentry.

If the exception happened before authorization, then the check_authorization
also raised, so Sentry saw a misleading CanCan::AuthorizationNotPerformed
error instead of the real one.

Let these exceptions propagate instead, so that they are reported correctly,
and are rendered by ErrorsController like any other unhandled exception.
app/controllers/api_controller.rb
test/controllers/api/nodes_controller_test.rb
test/controllers/api/users_controller_test.rb