Repository navigation
404 instead of 500 for malformed ids on public routes - #304
Merged
Merged
Conversation
/s/not-a-uuid and /api/files/not-a-uuid answered 500: the id went straight into a uuid column and Postgres rejected it with an error. The same applied to fetching, exporting and withdrawing a submission. isUuid() in packages/shared checks the id first. The status page lookup returns null (notFound), and the four API routes answer with their usual 404 body.
…id-id # Conflicts: # packages/shared/src/index.ts
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.
Problem
A URL with something that isn't a UUID, like
/s/not-a-uuid, answered 500 and wrote an error to the web log. Prisma passes the value to auuidcolumn and Postgres rejects it. Live today:/s/not-a-uuid→ 500,/api/files/not-a-uuid→ 500. The same path exists inapi/submissions/[id](delete),/exportand/withdraw.Fix
isUuid()inpackages/shared/src/uuid.ts.getSubmissionForStatusreturnsnullfor a malformed id, so the status page shows its normal 404.api/files/[id],api/submissions/[id],/exportand/withdrawanswer with their existing 404 body before touching the database.Tests
uuid.test.ts: canonical UUID in both cases accepted, the usual garbage rejected.pnpm --filter @msk-forms/shared test, typecheck of shared and web, eslint on the changed files.