Return a 404 if a Scratch project doesn't exist#749
Merged
zetter-rpf merged 1 commit intomainfrom Mar 27, 2026
Merged
Conversation
Test coverage89.69% line coverage reported by SimpleCov. |
4acbcea to
04610cf
Compare
Fixes RaspberryPiFoundation/digital-editor-issues#1269 Previously a 500 was raised if a scratch project wasn't found or we tried to load a project that was of another type. This is because these project don't have the expected ScratchComponents. Instead use the Rails Finders for loading, which will raise as expected if a record isn't found. I think this simplifies this code and removes the misleading locale lookup - Scratch API requests don't provide a locale so it's confusing to make them look like they do.
04610cf to
bbaa216
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the Scratch API project-loading behavior so missing or non-Scratch projects raise ActiveRecord::RecordNotFound (and therefore return HTTP 404 via ApiController), instead of triggering 500s when accessing Scratch-specific associations on nil/wrong-type projects.
Changes:
- Add request specs asserting 404 for missing projects and for projects that aren’t Scratch projects.
- Replace
ProjectLoaderusage in Scratch API controllers withProject.find_by!scoped to Scratch project type.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| spec/features/scratch/showing_a_scratch_project_spec.rb | Adds coverage for 404 responses when a project is missing or not Scratch. |
| app/controllers/api/scratch/scratch_controller.rb | Loads Scratch projects via find_by! to ensure missing/wrong-type projects yield 404. |
| app/controllers/api/scratch/projects_controller.rb | Loads original remix project via find_by! to ensure missing/wrong-type originals yield 404. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
abcampo-iry
approved these changes
Mar 27, 2026
Contributor
abcampo-iry
left a comment
There was a problem hiding this comment.
Thank you for the fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Status
What's changed?
Previously a 500 was raised if a scratch project wasn't found or we tried to load a project that was of another type. This is because these project don't have the expected ScratchComponents.
Instead use the Rails Finders for loading, which will raise as expected if a record isn't found. I think this simplifies this code and removes the misleading locale lookup - Scratch API requests don't provide a locale so it's confusing to make them look like they do.