nestjs-starter-rest-api icon indicating copy to clipboard operation
nestjs-starter-rest-api copied to clipboard

Unique constraint error while registering user with existing data

Open arifszn opened this issue 2 years ago • 0 comments

If a user with username x or email [email protected] is already registered, while registering with the same input, it throws 500 internal server error.

{
    "error": {
        "statusCode": 500,
        "message": "ER_DUP_ENTRY: Duplicate entry 'x' for key 'users.username'",
        "errorName": "QueryFailedError",
        "path": "/api/v1/auth/register",
        "requestId": "280f8680-1642-4518-9b51-c3ab57010e00",
        "timestamp": "2022-06-27T12:18:36.999Z"
    }
}

Handling while trying to register with existing data and throwing 400 Bad request would be more suitable instead of 500.

arifszn avatar Jun 27 '22 12:06 arifszn