Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UserResolver register's error handler doesn't work properly. (err code 23505) #30

Open
tmelent opened this issue Mar 28, 2021 · 0 comments

Comments

@tmelent
Copy link

tmelent commented Mar 28, 2021

Hello. In user.ts (user resolver) register function is catching and handling error with code 23505:

try {
      ...
    } catch (err) {
      //|| err.detail.includes("already exists")) {
      // duplicate username error
      if (err.code === "23505") {
        return {
          errors: [
            {
              field: "username",
              message: "username already taken",
            },
          ],
        };
      }
    }

But if you try to enter an e-mail that already exists in DB, it sends the same err code (23505) and detail field is similar to username error. key "(email)=asd@asd.com" already exists.
So I think it's correct to check if it includes 'email' or 'username' in it.

if (err.code === "23505") {
        if (err.detail.includes("email")){
          return {
            errors: [
              {
                field: "email",
                message: "email already taken",
              },
            ],
          };
        }
        return {
          errors: [
            {
              field: "username",
              message: "username already taken",
            },
          ],
        };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant