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 2 commits into
Conversation
This shouldn't be the case, since we declare 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
left a comment
There was a problem hiding this comment.
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.
|
Thank you for your review! I'm sorry for the late reply. I'll fix that asap 👍 |
|
I'm sorry I haven't been able to work on this because I've been so busy. I'll get to it as soon as possible. |
|
No worries. Don't feel rushed. |
Co-authored-by: Étienne Barrié <etienne.barrie@gmail.com>
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.