Handle malformed affiliate conversion bodies - #162
Conversation
Greptile SummaryThis PR fixes malformed JSON handling across all three mutation handlers (
Confidence Score: 5/5Safe to merge — the change is a targeted defensive improvement with no new logic paths that could cause regressions. All three mutation handlers now consistently guard against malformed JSON before touching the database, and each is covered by a dedicated regression test that confirms the 400 path and the absence of downstream DB calls. The safeParseBody utility is already used elsewhere in the codebase and its behavior is well-understood. No existing validated paths are altered. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Incoming Request] --> B[getAuthContext]
B -->|No auth| C[401 Unauthorized]
B -->|Authenticated| D[Query affiliate_offers]
D -->|Not found or wrong owner| E[403/404]
D -->|Offer owned by user| F[safeParseBody]
F -->|Returns null| G[400 Invalid request body]
F -->|Returns parsed object| H[Field Validation]
H -->|Invalid fields| I[400 field error]
H -->|Fields valid| J[DB Mutation / recordConversion]
J --> K[200/201 Response]
Reviews (2): Last reviewed commit: 2a4ee9e | Re-trigger Greptile |
| const noteText = typeof note === "string" ? note.trim() : null; | ||
| if (noteText) { | ||
| updateData.note = noteText; | ||
| } |
There was a problem hiding this comment.
When
note is an empty string, noteText evaluates to "" (falsy), so the database update is correctly skipped — but the response still returns note: "" rather than note: null. Before this change, the response used note?.trim() || null, which coerced empty-string back to null. The new approach creates a subtle inconsistency between what the response claims and what is actually stored in the database.
| const noteText = typeof note === "string" ? note.trim() : null; | |
| if (noteText) { | |
| updateData.note = noteText; | |
| } | |
| const noteText = typeof note === "string" && note.trim() ? note.trim() : null; | |
| if (noteText) { | |
| updateData.note = noteText; | |
| } |
Summary
Fixes #159
Verification