I have a nodejs server that can handle registering users. It interacts with a database and adds a new record given the values passed into it.
function registerUser(user) {
// Misc handling user
var isError = false;
userRepo.create(userData)
.catch((err) => {
isError = true
});
if (isError) {
return "Err"
}
}
The userRepo object is pretty much copied from this tutorial:
https://stackabuse.com/a-sqlite-tutorial-with-node-js/
In the catch block, I can console.log the error, but would like to return a value from the registerUser function if an error occurred. In the above code, the isError assignment inside of the catch block does not modify the isError defined above.
My question is : how can I write this so that a value indicating an error is returned from the registerUser function if an error occurs when creating the record?