0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-07 01:12:44 +00:00

Catch duplicate delete requests

This commit is contained in:
G.Ambatte
2023-06-25 21:26:02 +12:00
parent 4799e8b443
commit cff4f8eae5

View File

@@ -288,11 +288,14 @@ const api = {
try { try {
await api.getBrew('edit')(req, res, ()=>{}); await api.getBrew('edit')(req, res, ()=>{});
} catch (err) { } catch (err) {
// Only if the error code is HBErrorCode '02', that is, Google returned "404 - Not Found"
if(err.HBErrorCode == '02') {
const { id, googleId } = api.getId(req); const { id, googleId } = api.getId(req);
console.warn(`No google brew found for id ${googleId}, the stub with id ${id} will be deleted.`); console.warn(`No google brew found for id ${googleId}, the stub with id ${id} will be deleted.`);
await HomebrewModel.deleteOne({ editId: id }); await HomebrewModel.deleteOne({ editId: id });
return next(); return next();
} }
}
let brew = req.brew; let brew = req.brew;
const { googleId, editId } = brew; const { googleId, editId } = brew;