Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send 400 bad request error for no user-id header in api request #1988

Merged
merged 3 commits into from
Sep 26, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ export class UserCheckMiddleware {
public async use(req: AppRequest, res: AppRequest, next: express.NextFunction): Promise<any> {
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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well it's a bad request type, not really a user not found, the server has incomplete info to even try to find a user

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danoswaltCL Yeah, I was also thinking to add a new ERROR type: MISSING_HEADER_USER_ID. But, got an input from our playpower team to reuse existing one's. I know this is for logged in user data not found from DB. I will update this if the above type looks good to you.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screenshot 2024-09-26 at 2 04 58 PM

(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) {
Expand Down
Loading