wasp-lang / wasp

The fastest way to develop full-stack web apps with React & Node.js.
https://wasp-lang.dev
MIT License
13.64k stars 1.18k forks source link

Improve Prisma client error code to HTTP status code mapping #384

Open shayneczyzewski opened 2 years ago

shayneczyzewski commented 2 years ago

When saving things to the database with Prisma, many things can potentially go wrong. We need to indicate them to clients in ways that are actionable when they can correct them (e.g., status code 422 on bad input), or otherwise when they cannot (e.g., status code 500 when things are really wrong on backend).

We currently have a basic helper in place [waspc/data/Generator/templates/server/src/utils.js] that can check if an Error is a Prisma client error, and convert it to an HttpError. It is used during the sign up flow [waspc/data/Generator/templates/server/src/routes/auth/signup.js]. However, the mapping is incomplete. We need to thoroughly review https://www.prisma.io/docs/reference/api-reference/error-reference and determine what HTTP status code/message we should send from the controller to the frontend in each case.

This may also require refactoring the existing helpers, and allowing more flexible uses.

makinox commented 2 years ago

Hello, can I take this task?

weedertree commented 1 year ago

could you assign me with this issue

Martinsos commented 1 year ago

@weedertree last time we went after this one it proved to be a bit more complex than we expected. I will remove "good first issue" from it as I don't think is qualifies as one any more. If you do wish to go after this, I recommend giving a look at this PR https://github.com/wasp-lang/wasp/pull/744 and continuing conversation with that knowledge.