Skip to content

Commit

Permalink
handle bad requests and crashes
Browse files Browse the repository at this point in the history
  • Loading branch information
ssundahlTTD committed Nov 8, 2024
1 parent fd31cb8 commit f3ef70d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,18 @@ const EmailPromptRequest = z.object({
});

const handleEmailPromptSubmission: RequestHandler<{}, z.infer<typeof EmailPromptRequest>> = 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)) {
Expand Down Expand Up @@ -146,7 +154,7 @@ const defaultRouteHandler: RequestHandler<{}, {}, z.infer<typeof DefaultRouteReq
try {
requestStep = DefaultRouteRequest.parse(req.body).step;
} catch (e) {
logger.log('error', 'error while parsing the request');
logger.log('error', 'error while parsing step');
next(createError(500));
return;
}
Expand Down
4 changes: 4 additions & 0 deletions src/utils/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ const logger = createLogger({
}),
],
});
logger.exceptions.handle(new winston.transports.Console({
level: isProduction ? 'info' : 'debug',
}));
logger.exitOnError = false;

const headersToRedact = ['authorization', 'authentication'];

Expand Down

0 comments on commit f3ef70d

Please sign in to comment.