Skip to content

Commit

Permalink
fix: proxy repository error handling (#6142)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwasniew committed Feb 6, 2024
1 parent 067d130 commit cc060b7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
22 changes: 12 additions & 10 deletions src/lib/proxy/proxy-repository.ts
Expand Up @@ -64,7 +64,7 @@ export class ProxyRepository
this.configurationRevisionService =
services.configurationRevisionService;
this.token = token;
this.onAnyEvent = this.onAnyEvent.bind(this);
this.onUpdateRevisionEvent = this.onUpdateRevisionEvent.bind(this);
this.interval = config.frontendApi.refreshIntervalInMs;
}

Expand All @@ -87,14 +87,20 @@ export class ProxyRepository

// Reload cached token data whenever something relevant has changed.
// For now, simply reload all the data on any EventStore event.
this.configurationRevisionService.on(UPDATE_REVISION, this.onAnyEvent);
this.configurationRevisionService.on(
UPDATE_REVISION,
this.onUpdateRevisionEvent,
);

this.emit(UnleashEvents.Ready);
this.emit(UnleashEvents.Changed);
}

stop(): void {
this.configurationRevisionService.off(UPDATE_REVISION, this.onAnyEvent);
this.configurationRevisionService.off(
UPDATE_REVISION,
this.onUpdateRevisionEvent,
);
this.running = false;
}

Expand Down Expand Up @@ -122,20 +128,16 @@ export class ProxyRepository
this.features = await this.featuresForToken();
this.segments = await this.segmentsForToken();
} catch (e) {
this.logger.error(e);
this.logger.error('Cannot load data for token', e);
}
}

private randomizeDelay(floor: number, ceiling: number): number {
return Math.floor(Math.random() * (ceiling - floor) + floor);
}

private async onAnyEvent() {
try {
await this.loadDataForToken();
} catch (error) {
this.logger.error(error);
}
private async onUpdateRevisionEvent() {
await this.loadDataForToken();
}

private async featuresForToken(): Promise<FeatureInterface[]> {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/services/user-feedback-service.ts
Expand Up @@ -27,7 +27,7 @@ export default class UserFeedbackService {
try {
return await this.userFeedbackStore.getAllUserFeedback(user.id);
} catch (err) {
this.logger.error(err);
this.logger.error('Cannot read user feedback', err);
return [];
}
}
Expand Down

0 comments on commit cc060b7

Please sign in to comment.