Skip to content

Commit

Permalink
Don't crash if we are unable to get a response from the feature-flag …
Browse files Browse the repository at this point in the history
…endpoint.
  • Loading branch information
Cornelius Riemenschneider authored and GitHub committed Jul 18, 2022
1 parent d8c9c72 commit 01fa64c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
9 changes: 7 additions & 2 deletions lib/feature-flags.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/feature-flags.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions src/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,21 @@ export class GitHubFeatureFlags implements FeatureFlags {
) {}

async getValue(flag: FeatureFlag): Promise<boolean> {
const response = (await this.getApiResponse())[flag];
const response = await this.getApiResponse();
if (response === undefined) {
this.logger.debug(
`No feature flags API response for ${flag}, considering it disabled.`
);
return false;
}
const flag_value = response[flag];
if (flag_value === undefined) {
this.logger.debug(
`Feature flag '${flag}' undefined in API response, considering it disabled.`
);
return false;
}
return response;
return flag_value;
}

private async getApiResponse(): Promise<FeatureFlagsApiResponse> {
Expand Down

0 comments on commit 01fa64c

Please sign in to comment.