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 1 year 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

@aliamerj is attempting to deploy a commit to the Dub Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar May 04 '24 18:05 vercel[bot]

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar May 04 '24 18:05 CLAassistant

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
dub ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 6, 2024 8:47am

vercel[bot] avatar May 05 '24 20:05 vercel[bot]

Brilliant work, thank you @aliamerj!

steven-tey avatar May 06 '24 13:05 steven-tey

Thanks

aliamerj avatar May 06 '24 13:05 aliamerj