Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postData query has no .catch() #28

Open
rooberrydev opened this issue Dec 20, 2019 · 0 comments
Open

postData query has no .catch() #28

rooberrydev opened this issue Dec 20, 2019 · 0 comments
Assignees

Comments

@rooberrydev
Copy link

return dbConnection.query(
"INSERT INTO users (name, behaviour, category) VALUES ($1, $2, $3)",
[userInformation.name, userInformation.behaviour, userInformation.category]
);

there is no .catch(), but this is alright(it will still throw a 500 error as expected) since .query will return a rejected promise with the value of err anyway.

postData({
name: req.body.username,
behaviour: goodOrBad,
category: req.body.category
})
.then(responseDb => {
res.redirect("/presents");
})
.catch(error => {
throw error;
});

since you are throwing this error when calling postData, the 500 handler will take care of this.

but in case you dont want to pass the entire error around(maybe just err.message for example), or if you want to console.log the error at the query stage instead of in your controller, adding a .then() for the response, and a .catch() for the error would help.

@roshlarosh roshlarosh self-assigned this Dec 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants