From 4ab7e41e570fb8910a3ccaf43481c3200ac0f946 Mon Sep 17 00:00:00 2001 From: Ashley Smith Date: Mon, 29 Jul 2024 17:12:10 -0600 Subject: [PATCH] define step outside try catch --- src/routes/index.ts | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/routes/index.ts b/src/routes/index.ts index e1f02f3..d240238 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -138,22 +138,26 @@ const DefaultRouteRequest = z.object({ }); const defaultRouteHandler: RequestHandler<{}, {}, z.infer> = async (req, res, next) => { + let step; + try { - const { step } = DefaultRouteRequest.parse(req.body); - if (!step) { - throw new Error('no step'); - } - const handler = Object.prototype.hasOwnProperty.call(steps, step) && steps[step]; - if (!handler) { - throw new Error(`invalid step ${step}`); - } - - await handler(req, res, next); + step = DefaultRouteRequest.parse(req.body).step; } catch (e) { logger.log('error', `error while parsing the request`); + return; } + if (!step) { + throw new Error('no step'); + } + const handler = Object.prototype.hasOwnProperty.call(steps, step) && steps[step]; + if (!handler) { + throw new Error(`invalid step ${step}`); + } + + await handler(req, res, next); +