-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Title: TypeError when handling SequelizeUniqueConstraintError in signup function
Description
In the signup function of the user controller, a TypeError occurs when trying to handle a SequelizeUniqueConstraintError. The error happens because the code attempts to destructure error.fields, which does not exist. The correct property to use is error.errors, an array of error objects.
Steps to Reproduce
- Attempt to sign up a new user with a username that already exists in the database.
- Observe the
TypeErrorlogged in the console.
Expected Behavior
The function should handle the unique constraint violation properly and return a 409 Conflict status with an appropriate error message.
Actual Behavior
A TypeError occurs due to an attempt to destructure error.fields, which does not exist. The error details indicate that the unique constraint was violated.
Proposed Solution
Update the error handling to use error.errors instead of error.fields. The corrected code should be:
if (error instanceof UniqueConstraintError) {
const alreadyExistingField = error.errors[0].path;
errorMsgSender(res, 409, `${alreadyExistingField} already exists`);
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels