diff --git a/backend/packages/Upgrade/src/api/middlewares/UserCheckMiddleware.ts b/backend/packages/Upgrade/src/api/middlewares/UserCheckMiddleware.ts index 69d3eee464..9ebeedf8cd 100644 --- a/backend/packages/Upgrade/src/api/middlewares/UserCheckMiddleware.ts +++ b/backend/packages/Upgrade/src/api/middlewares/UserCheckMiddleware.ts @@ -12,8 +12,16 @@ export class UserCheckMiddleware { public async use(req: AppRequest, res: AppRequest, next: express.NextFunction): Promise { try { const user_id = req.get('User-Id'); - req.logger.child({ user_id }); - req.logger.debug({ message: 'User Id is:', user_id }); + if (!user_id) { + const error = new Error(`User-Id header not found.`); + (error as any).type = SERVER_ERROR.USER_NOT_FOUND; + (error as any).httpCode = 400; + req.logger.error(error); + return next(error); + } else { + req.logger.child({ user_id }); + req.logger.debug({ message: 'User Id is:', user_id }); + } const experimentUserDoc = await this.experimentUserService.getUserDoc(user_id, req.logger); if (!req.url.endsWith('/init') && !experimentUserDoc) {