You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Line 35, the .catch() is catching errors on bcrypt stuff.
but there's another promise chain that is started once hashing is complete, and this is the database insert request - usersModel.addUser.
This does error when you try and create a username that already exists (because you have the UNIQUE keyword on the username table in the database) causing the app to crash due to an unhandled promise rejection.
`INSERT INTO users (username, password, cohort)VALUES($1, $2, $3);`,
[username,password,cohort]
)
.then((res)=>res.rows);
}
addUser, if it were to fail, would return a rejected promise with the error as the value.
and then on the other side (back in the addUserHandler), you can add a .catch() to pass on this error to the error handler middleware.
week7-hihi/handlers/users-handler.js
Lines 21 to 36 in 68325ba
Line 35, the .catch() is catching errors on bcrypt stuff.
but there's another promise chain that is started once hashing is complete, and this is the database insert request - usersModel.addUser.
This does error when you try and create a username that already exists (because you have the UNIQUE keyword on the username table in the database) causing the app to crash due to an unhandled promise rejection.
week7-hihi/model/users-model.js
Lines 26 to 33 in 68325ba
addUser, if it were to fail, would return a rejected promise with the error as the value.
and then on the other side (back in the addUserHandler), you can add a .catch() to pass on this error to the error handler middleware.
notice the two .catch(), one for the bcrypt promise chain and one for the database query promise chain.
TL:DR,
week7-hihi/handlers/users-handler.js
Lines 27 to 28 in 68325ba
you have an uncaught promise exception which can be fixed by adding a .catch(next) to usersModel.addUser
The text was updated successfully, but these errors were encountered: