From 544f1fb017bc893bc5c67c17e59ca8c5da72b294 Mon Sep 17 00:00:00 2001 From: Enstrayed <48845980+Enstrayed@users.noreply.github.com> Date: Thu, 2 May 2024 17:36:54 -0700 Subject: [PATCH] fix crash in case database entry is malformed --- routes/etyd.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/routes/etyd.js b/routes/etyd.js index fef00c5..24abbc7 100644 --- a/routes/etyd.js +++ b/routes/etyd.js @@ -10,7 +10,12 @@ app.get("/etyd*", (rreq,rres) => { rres.sendStatus(404) } else { dbRes.json().then(dbRes => { - rres.redirect(dbRes.content.url) + try { + rres.redirect(dbRes.content.url) // Node will crash if the Database entry is malformed + } catch (responseError) { + rres.sendStatus(500) + console.log(`${rres.get("cf-connecting-ip")} GET ${rreq.path} returned 500: ${responseError}`) + } }) } }).catch(fetchError => {