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
TypeError logged 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`);
}
Title: TypeError when handling SequelizeUniqueConstraintError in
signupfunctionDescription
In the
signupfunction of the user controller, aTypeErroroccurs when trying to handle aSequelizeUniqueConstraintError. The error happens because the code attempts to destructureerror.fields, which does not exist. The correct property to use iserror.errors, an array of error objects.Steps to Reproduce
TypeErrorlogged in the console.Expected Behavior
The function should handle the unique constraint violation properly and return a
409 Conflictstatus with an appropriate error message.Actual Behavior
A
TypeErroroccurs due to an attempt to destructureerror.fields, which does not exist. The error details indicate that the unique constraint was violated.Proposed Solution
Update the error handling to use
error.errorsinstead oferror.fields. The corrected code should be: