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

Update getKeys to respond 404 when /featureflag is requested without /init #1805

Merged
merged 4 commits into from
Aug 9, 2024

Conversation

zackcl
Copy link
Collaborator

@zackcl zackcl commented Aug 6, 2024

Resolves #1802

bcb37
bcb37 previously requested changes Aug 6, 2024
Copy link
Collaborator

@bcb37 bcb37 left a 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}` });
Copy link
Collaborator

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)

Copy link
Collaborator Author

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.

Copy link
Collaborator Author

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

@danoswaltCL danoswaltCL dismissed bcb37’s stale review August 9, 2024 19:05

zack implemented this change

@danoswaltCL danoswaltCL merged commit 4da62af into dev Aug 9, 2024
8 checks passed
@danoswaltCL danoswaltCL deleted the bugfix/1802-featureflag-response branch August 9, 2024 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Requesting /featureflag without /init should return a proper 404 response
3 participants