Skip to content

Commit

Permalink
define step outside try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
ashleysmithTTD committed Jul 29, 2024
1 parent 0dd4950 commit 4ab7e41
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,22 +138,26 @@ const DefaultRouteRequest = z.object({
});

const defaultRouteHandler: RequestHandler<{}, {}, z.infer<typeof DefaultRouteRequest>> = 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);




Expand Down

0 comments on commit 4ab7e41

Please sign in to comment.