From f3ef70d4be5957add4fe508705316f7157d8f28f Mon Sep 17 00:00:00 2001 From: Scott Sundahl Date: Fri, 8 Nov 2024 09:06:06 -0700 Subject: [PATCH] handle bad requests and crashes --- src/routes/index.ts | 10 +++++++++- src/utils/logging.ts | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/routes/index.ts b/src/routes/index.ts index c34185f..bd0926f 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -55,10 +55,18 @@ const EmailPromptRequest = z.object({ }); const handleEmailPromptSubmission: RequestHandler<{}, z.infer> = async (req, res, _next) => { + try { + EmailPromptRequest.parse(req.body); + } catch (e) { + logger.log('error', 'error while parsing the request'); + _next(createError(500)); + return; + } const { email, countryCode, phone, recaptcha, idType, } = EmailPromptRequest.parse(req.body); + let idInput = ''; if (ID_TYPE === 'EUID') { if (!isValidEmail(email)) { @@ -146,7 +154,7 @@ const defaultRouteHandler: RequestHandler<{}, {}, z.infer