dub icon indicating copy to clipboard operation
dub copied to clipboard

Quick Fix: Inconsistent Error Responses for Invalid JSON in API Requests

Open aliamerj opened this issue 3 months ago • 3 comments

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!

aliamerj avatar May 04 '24 18:05 aliamerj