0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-03 17:02:40 +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,10 +288,13 @@ const api = {
try { try {
await api.getBrew('edit')(req, res, ()=>{}); await api.getBrew('edit')(req, res, ()=>{});
} catch (err) { } catch (err) {
const { id, googleId } = api.getId(req); // Only if the error code is HBErrorCode '02', that is, Google returned "404 - Not Found"
console.warn(`No google brew found for id ${googleId}, the stub with id ${id} will be deleted.`); if(err.HBErrorCode == '02') {
await HomebrewModel.deleteOne({ editId: id }); const { id, googleId } = api.getId(req);
return next(); console.warn(`No google brew found for id ${googleId}, the stub with id ${id} will be deleted.`);
await HomebrewModel.deleteOne({ editId: id });
return next();
}
} }
let brew = req.brew; let brew = req.brew;