Skip to content

Commit

Permalink
fix: updates after PR discussion
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswk committed Nov 20, 2023
1 parent 56d5908 commit 404d610
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export default class Metrics extends EventEmitter {
}

getInterval(): number {
if(this.metricsInterval === 0 || this.failures === -1) {
if(this.metricsInterval === 0) {
return 0;
} else {
return this.metricsInterval +
Expand Down Expand Up @@ -190,16 +190,16 @@ export default class Metrics extends EventEmitter {
return true;
}

unrecoverableError(url: string, statusCode: number) {
configurationError(url: string, statusCode: number) {
this.emit(UnleashEvents.Warn, `${url} returning ${statusCode}, stopping metrics`);
this.failures = -1;
this.metricsInterval = 0;
this.stop();
}

backoff(url: string, statusCode: number): void {
this.failures = Math.min(10, this.failures + 1);
// eslint-disable-next-line max-len
this.emit(UnleashEvents.Warn, `${url} returning ${statusCode}. Backing off to ${this.getInterval()}`);
this.emit(UnleashEvents.Warn, `${url} returning ${statusCode}. Backing off to ${this.failures} times normal interval`);
this.startTimer();
}

Expand Down Expand Up @@ -229,7 +229,7 @@ export default class Metrics extends EventEmitter {
});
if (!res.ok) {
if (res.status === 404 || res.status === 403 || res.status == 401) {
this.unrecoverableError(url, res.status);
this.configurationError(url, res.status);
} else if (
res.status === 429 ||
res.status === 500 ||
Expand Down
4 changes: 2 additions & 2 deletions src/repository/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ Message: ${err.message}`,

// Emits correct error message based on what failed,
// and returns 0 as the next fetch interval (stop polling)
private unrecoverableError(url: string, statusCode: number): number {
private configurationError(url: string, statusCode: number): number {
this.failures += 1;
if (statusCode === 404) {
this.emit(
Expand Down Expand Up @@ -309,7 +309,7 @@ Message: ${err.message}`,

private handleErrorCases(url: string, statusCode: number): number {
if (statusCode === 401 || statusCode === 403 || statusCode === 404) {
return this.unrecoverableError(url, statusCode);
return this.configurationError(url, statusCode);
} else if (
statusCode === 429 ||
statusCode === 500 ||
Expand Down

0 comments on commit 404d610

Please sign in to comment.