#Is it bad practice to depend on the unique constraint while creating a new object?

16 messages · Page 1 of 1 (latest)

chilly leaf
#

In my example: I have a User model with unique email. Should I be checking beforehand if the email already exists or does it not really matter because it will throw an error?

sonic mapleBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

carmine mauve
#

Ii'll reply again i didn't like my previous answer. If you set the email field to unique you'll get an error if you try to use the same email to create another account. You just manage the error properly.

#

You should have a banner in your website that display the errors that come from the backend

#

a reusable banner let's say

twilit oriole
#

If it is a unique key on your database, it will throw an error.

chilly leaf
#

Its revealing more to the user than they need to

#

But atm for every error (because this really should be my only prisma error) I have a message: "An error occured while creating your account. You may already have an existing account with this email address."

carmine mauve
#

nope, just translate it into something different

chilly leaf
#

ig but generic errors is what ur supposed to do

twilit oriole
#

But shortening the conversation, you should change your error message to a more generic one

chilly leaf
#

Even google says that if your signing up

#

A random error is worse because that doesn't tell the user to switch their email and they will be unable to signup