recover gracefully when admin views deleted project #26693
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
https://app.honeybadger.io/projects/3240/faults/44663286 indicates that admins are getting 500 when following urls to deleted projects. This is because the admin panel displays content moderation info
code-dot-org/dashboard/app/views/levels/_admin.html.haml
Lines 88 to 90 in f9bf7c8
code-dot-org/shared/middleware/helpers/storage_apps.rb
Lines 209 to 213 in a23e3ca
Description
The solution is to not raise for deleted projects. In the admin panel this suppresses any errors long enough for the page to redirect. This is also harmless for non-admins in production, since an earlier lookup to the project would 404 prior to any 404 being generated by the line modified in this PR:
code-dot-org/shared/middleware/files_api.rb
Line 875 in 6269b4b
Testing
Manually verified that when an admin views a deleted project, they now get redirected to their latest project of that type instead of seeing a 500 error.