Skip to content

Commit 8ddeae9

Browse files
add duplicate username error check
1 parent ed0260b commit 8ddeae9

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

controllers/Temp.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6194,8 +6194,17 @@ class TempController {
61946194

61956195
return resolve(HTTPWTHandler.OK('Profile details were successfully edited'))
61966196
}).catch(error => {
6197-
console.error('An error occurred while updating user profiles. The user detail object was:', profileDetails, '. The error was:', error)
6198-
return resolve(HTTPWTHandler.serverError('An error occurred while updating profile details. Please try again.'))
6197+
if (error.codeName === 'DuplicateKey') {
6198+
if (Object.keys(error.keyValue)[0] === 'name') {
6199+
return resolve(HTTPWTHandler.conflict('Another SocialSquare user has the username you are trying to use. Please choose a different username.'))
6200+
} else {
6201+
console.error('An unknown key is giving a duplicate error while updating profile details. The error is:', error)
6202+
return resolve(HTTPWTHandler.serverError('An unknown key cannot be duplicated.'))
6203+
}
6204+
} else {
6205+
console.error('An error occurred while updating user profiles. The user detail object was:', profileDetails, '. The error was:', error)
6206+
return resolve(HTTPWTHandler.serverError('An error occurred while updating profile details. Please try again.'))
6207+
}
61996208
})
62006209
})
62016210
}

0 commit comments

Comments
 (0)