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

Always catch errors and send back something #9

Open
cchauche opened this issue May 22, 2021 · 0 comments
Open

Always catch errors and send back something #9

cchauche opened this issue May 22, 2021 · 0 comments

Comments

@cchauche
Copy link

router.get('/', (req, res) => {
const { product_id } = req.query;
ProductMeta.findOne({product_id})
.then((metaData) => {
const inputCharac = metaData.characteristics;
const outputCharac = {};
inputCharac.map((charac) => {
if (charac.count) {
outputCharac[charac.name] = {
value: charac.avgValue,
count: charac.count,
id: charac.characteristic_id
};
}
});
metaData.characteristics = outputCharac;
res.status(200).send(metaData);
})
});

It looks like there is is no catch for this DB transaction so if it fails the client would never get a response. Remember to always send back a response even when there is an error.

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

1 participant