dub
dub copied to clipboard
Quick Fix: Inconsistent Error Responses for Invalid JSON in API Requests
When sending invalid JSON to PATCH /links/{linkId}
and POST /links/bulk
, we're getting an "internal server error" instead of the more helpful "bad request" error.
However, POST /links
gets it right and tells us it's a "bad request" due to invalid JSON.
I believe this will help everyone using the API to have a smoother and more predictable experience.
I've already fixed it by first checking:
const bodyRaw = await parseRequestBody(req);
const links = bulkCreateLinksBodySchema.parse(bodyRaw);
I hope this helps make Dub better!