From 4951b9bf1ab32845f45bc1490bd4fb2abd595d4a Mon Sep 17 00:00:00 2001 From: Trevor Buckner Date: Sat, 13 Jul 2024 19:46:12 -0400 Subject: [PATCH] Add async error handler to /edit and /new Since /edit and /new endpoints now have an `await` inside that could return an error (`getUsersBrewThemes()`), asyncHandler must be added to pass errors along instead of just crashing --- server/app.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/app.js b/server/app.js index 99ad650d7..d0160e3d0 100644 --- a/server/app.js +++ b/server/app.js @@ -271,7 +271,7 @@ app.get('/user/:username', async (req, res, next)=>{ }); //Edit Page -app.get('/edit/:id', asyncHandler(getBrew('edit')), async(req, res, next)=>{ +app.get('/edit/:id', asyncHandler(getBrew('edit')), asyncHandler(async(req, res, next)=>{ req.brew = req.brew.toObject ? req.brew.toObject() : req.brew; req.userThemes = await(getUsersBrewThemes(req.account?.username)); @@ -287,10 +287,10 @@ app.get('/edit/:id', asyncHandler(getBrew('edit')), async(req, res, next)=>{ splitTextStyleAndMetadata(req.brew); res.header('Cache-Control', 'no-cache, no-store'); //reload the latest saved brew when pressing back button, not the cached version before save. return next(); -}); +})); //New Page -app.get('/new/:id', asyncHandler(getBrew('share')), (req, res, next)=>{ +app.get('/new/:id', asyncHandler(getBrew('share')), asyncHandler(async(req, res, next)=>{ sanitizeBrew(req.brew, 'share'); splitTextStyleAndMetadata(req.brew); const brew = { @@ -312,7 +312,7 @@ app.get('/new/:id', asyncHandler(getBrew('share')), (req, res, next)=>{ }; return next(); -}); +})); //Share Page app.get('/share/:id', asyncHandler(getBrew('share')), asyncHandler(async (req, res, next)=>{