-
Notifications
You must be signed in to change notification settings - Fork 109
Handle Task::NotFoundError with a 404 page instead of raising an error#1440
Handle Task::NotFoundError with a 404 page instead of raising an error #1440kaibadash wants to merge 1 commit into
Conversation
etiennebarrie
commented
Apr 7, 2026
2. Was reported to error monitoring systems (e.g., Sentry) as an unhandled exception, creating noise
This shouldn't be the case, since we declare NotFoundError as a rescuable exception that results in a 404:
maintenance_tasks/lib/maintenance_tasks/engine.rb
Lines 36 to 38 in 4b8ef60
$ bin/production & $ curl -s -D - http://127.0.0.1:3000/maintenance_tasks/tasks/DoesNotExist | grep 404 HTTP/1.1 404 Not Found <title>The page you were looking for doesn't exist (404)</title> <!-- This file lives in public/404.html -->
Maybe Sentry's code does still mark those as unhandled exceptions, but then it's a bug/feature in their code.
@etiennebarrie
etiennebarrie
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be nice.
At first I thought that shouldn't be necessary (easy enough to tweak the URL), and the Sentry issue is a problem with that gem or the configuration (although it shouldn't be necessary to add this exception class to list of excluded exceptions, doing so would solve that issue).
But the change is small, the page looks nicer (and also the main app's 404 page might be super custom) and moving away from action_dispatch.rescue_responses means better support for exception monitoring tools which don't respect action_dispatch.report_exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish we could explicitly test the 404 but we can't use page.status_code 😞
However the 404 causes an issue with
kaibadash
commented
Apr 17, 2026
Thank you for your review! I'm sorry for the late reply. I'll fix that asap 👍
rescue_from Task::NotFoundErrorinApplicationControllerto render a friendly 404 page when users access a task that no longer existsnot_found.html.erb) styled with Bulma to match the existing UI, with a link back to the tasks listrescue_responsesmapping fromEnginesince the error is now handled directly by the controllerMotivation
Maintenance tasks are short-lived by nature — they are created for one-time data migrations or cleanup operations and are expected to be deleted once they are no longer needed. However, users may still have bookmarked URLs or links in Slack/docs pointing to deleted tasks.
Previously, accessing a deleted task with no associated runs raised
MaintenanceTasks::Task::NotFoundError, which:By using
rescue_fromin the controller, the exception is caught before it propagates to error monitoring middleware, and users see a clean 404 page with navigation back to the task list.