Return 400 for malformed application status JSON#465
Conversation
Greptile SummaryThis PR adds guarded JSON parsing to the
Confidence Score: 5/5Safe to merge — the change is narrow and additive, inserting one small helper that wraps an existing call and adding a matching test. The parseJsonBody helper correctly catches the one error case (request.json() throwing on bad input), returns early before any database access, and leaves all existing code paths untouched. The new test verifies both the HTTP status code and that Supabase is never called, giving solid coverage of the new branch. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant PUT Handler
participant getAuthContext
participant parseJsonBody
participant Supabase
Client->>PUT Handler: PUT /api/applications/[id]/status
PUT Handler->>getAuthContext: authenticate request
getAuthContext-->>PUT Handler: null (unauth) or { user, supabase }
alt Unauthenticated
PUT Handler-->>Client: 401 Unauthorized
else Authenticated
PUT Handler->>parseJsonBody: request.json()
alt Malformed JSON (new path)
parseJsonBody-->>PUT Handler: { response: 400 }
PUT Handler-->>Client: 400 Invalid JSON body
else Valid JSON
parseJsonBody-->>PUT Handler: { body: ... }
PUT Handler->>PUT Handler: applicationStatusSchema.safeParse(body)
alt Schema invalid
PUT Handler-->>Client: 400 validation error
else Schema valid
PUT Handler->>Supabase: select application
PUT Handler->>Supabase: select gig
PUT Handler->>Supabase: update application
PUT Handler-->>Client: 200 { application }
end
end
end
Reviews (2): Last reviewed commit: "Handle malformed application status JSON" | Re-trigger Greptile |
3c1adee to
260838e
Compare
|
CI is green after rebasing this PR onto the latest master. Verification:
The earlier unrelated full-suite failure no longer reproduces. |
Closes #464.
Summary
PUT /api/applications/[id]/status.400 Invalid JSON bodyfor malformed request JSON before Supabase queries.Verification
corepack pnpm vitest run 'src/app/api/applications/[id]/status/route.test.ts'corepack pnpm tsc --noEmit