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
Merged
Changes from all commits
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
23 changes: 21 additions & 2 deletions backend/packages/Upgrade/src/api/services/FeatureFlagService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { ExperimentUser } from '../models/ExperimentUser';
import { ExperimentAssignmentService } from './ExperimentAssignmentService';
import { SegmentService } from './SegmentService';
import { ErrorWithType } from '../errors/ErrorWithType';
import { RequestedExperimentUser } from '../controllers/validators/ExperimentUserValidator';

@Service()
export class FeatureFlagService {
Expand All @@ -38,8 +39,26 @@ export class FeatureFlagService {
return this.featureFlagRepository.find();
}

public async getKeys(experimentUserDoc: ExperimentUser, context: string, logger: UpgradeLogger): Promise<string[]> {
logger.info({ message: 'Get all feature flags' });
public async getKeys(
experimentUserDoc: RequestedExperimentUser,
context: string,
logger: UpgradeLogger
): Promise<string[]> {
logger.info({ message: `getKeys: User: ${experimentUserDoc?.requestedUserId}` });

// throw error if user not defined
if (!experimentUserDoc || !experimentUserDoc.id) {
logger.error({ message: 'User not defined in getKeys' });
const error = new Error(
JSON.stringify({
type: SERVER_ERROR.EXPERIMENT_USER_NOT_DEFINED,
message: 'User not defined in getKeys',
})
);
(error as any).type = SERVER_ERROR.EXPERIMENT_USER_NOT_DEFINED;
(error as any).httpCode = 404;
throw error;
}

const filteredFeatureFlags = await this.featureFlagRepository.getFlagsFromContext(context);

Expand Down
Loading