I have unique column in mysql database when and duplicate entry occur's it gives Error: ER_DUP_ENTRY: Duplicate entry how to handle the error form nodejs
Put the save onto try block and catch all errors. add a specific check for duplicates and handle the rest as defaults
try {
return await this.userProfilesRepository.save(userProfile);
} catch (err) {
if (err.code === 'ER_DUP_ENTRY') {
//handleHttpErrors(SYSTEM_ERRORS.USER_ALREADY_EXISTS);
} else {
//handleHttpErrors(err.message);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With