fix(table): return 400 instead of 500 on empty batch insert#4329
fix(table): return 400 instead of 500 on empty batch insert#4329waleedlatif1 merged 1 commit intostagingfrom
Conversation
The POST /api/table/[tableId]/rows handler called handleBatchInsert without await, so ZodError rejections (e.g. empty rows array) bypassed the route's try/catch and were caught by withRouteHandler as an unhandled error, returning a generic 500 "Internal server error". Add await so validation errors surface as 400s with the actual message.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryLow Risk Overview This ensures Zod/validation failures in batch insert requests (e.g., empty Reviewed by Cursor Bugbot for commit 989ecd1. Configure here. |
Greptile SummaryThis PR adds a missing Confidence Score: 5/5This PR is safe to merge — it's a minimal, correct one-word fix with no regressions. Single-character change ( No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant withRouteHandler
participant POST Handler
participant handleBatchInsert
participant ZodSchema
Client->>withRouteHandler: POST /api/table/[tableId]/rows {rows:[]}
withRouteHandler->>POST Handler: invoke
rect rgb(200, 240, 200)
Note over POST Handler,ZodSchema: After fix (await present)
POST Handler->>handleBatchInsert: await handleBatchInsert(...)
handleBatchInsert->>ZodSchema: BatchInsertRowsSchema.parse({rows:[]})
ZodSchema-->>handleBatchInsert: throws ZodError
handleBatchInsert-->>POST Handler: rejected Promise
POST Handler->>POST Handler: catch(error) — ZodError instanceof z.ZodError
POST Handler-->>Client: 400 { error: "Validation error", details: [...] }
end
rect rgb(255, 200, 200)
Note over POST Handler,ZodSchema: Before fix (no await)
POST Handler->>handleBatchInsert: handleBatchInsert(...) [no await]
handleBatchInsert->>ZodSchema: BatchInsertRowsSchema.parse({rows:[]})
ZodSchema-->>handleBatchInsert: throws ZodError
handleBatchInsert-->>POST Handler: unhandled Promise rejection
POST Handler-->>withRouteHandler: uncaught rejection
withRouteHandler-->>Client: 500 "Internal server error"
end
Reviews (1): Last reviewed commit: "fix(table): return 400 instead of 500 on..." | Re-trigger Greptile |
Summary
/api/table/[tableId]/rowscalledhandleBatchInsertwithoutawait, so ZodError rejections (e.g. emptyrowsarray) bypassed the route's try/catch and were caught bywithRouteHandleras an unhandled error — returning a generic 500 "Internal server error"awaitso validation errors surface as proper 400s with the actual message (e.g. "At least one row is required")Type of Change
Testing
Tested manually
Checklist