Skip to content

Commit

Permalink
fix: decrease on errors
Browse files Browse the repository at this point in the history
  • Loading branch information
simllll committed May 3, 2021
1 parent ca62dd8 commit 36cdf7f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ export class AxiosRateLimit {
options?.keyGenerator ||
((_request: AxiosRequestConfig) => `axios-rate-limit-${this.instanceId}`);

function handleError(error: Error) {
return Promise.reject(error);
}
axios.interceptors.request.use(this.handleRequest.bind(this), this.handleError.bind(this));
axios.interceptors.response.use(this.handleResponse.bind(this), this.handleError.bind(this));
}

handleError(error: any) {
const key = this.keyGenerator(error.config);

this.store.decrement(key);

axios.interceptors.request.use(this.handleRequest.bind(this), handleError);
axios.interceptors.response.use(this.handleResponse.bind(this), handleError);
return Promise.reject(error);
}

getMaxRPS(): number {
Expand Down

0 comments on commit 36cdf7f

Please sign in to comment.