-
Notifications
You must be signed in to change notification settings - Fork 14
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
Update getKeys to respond 404 when /featureflag is requested without /init #1805
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One suggestion.
|
||
// throw error if user not defined | ||
if (!experimentUserDoc || !experimentUserDoc.id) { | ||
logger.error({ message: `User not defined in getAllExperimentConditions: ${experimentUserDoc?.id}` }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
experimentUserDoc?.id
in that interpolated string will never be anything but undefined. We should probably just throw a more generic message. (same on line 50 below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I've updated the code so that it logs with experimentUserDoc?.requestedUserId
instead of experimentUserDoc?.id
which will always be undefined. This is exactly the same as how we log and return 404 in the getAllExperimentConditions
function.
However, in the current code, the experimentUserDoc?.requestedUserId
is also undefined
when the user document is not found. This is due to how the getUserDoc
function is currently implemented:
public async getUserDoc(experimentUserId, logger): Promise<RequestedExperimentUser> {
try {
const experimentUserDoc = await this.getOriginalUserDoc(experimentUserId, logger);
if (experimentUserDoc) {
const userDoc = { ...experimentUserDoc, requestedUserId: experimentUserId };
logger.info({ message: 'Got the user doc', details: userDoc });
return userDoc;
} else {
return null;
}
} catch (error) {
logger.error({ message: `Error in getting user doc for user => ${experimentUserId}`, error });
return null;
}
}
I believe this should be updated to the following to allow logging experimentUserDoc?.requestedUserId
when the user document is not found:
public async getUserDoc(experimentUserId: string, logger: UpgradeLogger): Promise<RequestedExperimentUser | null> {
try {
const experimentUserDoc = await this.getOriginalUserDoc(experimentUserId, logger);
const userDoc = { ...experimentUserDoc, requestedUserId: experimentUserId };
logger.info({ message: 'Got the user doc', details: userDoc });
return userDoc;
} catch (error) {
logger.error({ message: `Error in getting user doc for user => ${experimentUserId}`, error });
return null;
}
}
I can create a separate PR to apply this change. Please feel free to approve this one if this makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created a PR to update the getUserDoc
function : #1809
…equestedUserId for consistency
Resolves #1802