When executing a query using Objection.js, the result of the query will be passed to the then() block as either 0 or 1 depending on its success or failure. Instead of handling errors in the catch block, I find myself checking falsey values. Is there a better way to approach this situation?
const editIndustry = async (req, res, next) => {
const industry = await Industry.query().findById(req.params.industryId);
if (!industry) {
return res.status(404).json({
error: 'NotFoundError',
message: `industry not found`,
});
}
await industry
.$query()
.patch({ ...req.body })
.then(result => console.log(result, 'then() block'))
// never runs
.catch(err => {
console.log(err);
next(err);
});
};
Server is running and listening on port 3000.
The then() block executed successfully once.