Skip to content

Commit

Permalink
🔨 The actual fix for re-requesting token from ptf when 401 (tested it)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobotoLev committed May 31, 2022
1 parent d66203e commit 0a36455
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/lib/pricer/pricestf/prices-tf-api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios, { AxiosRequestConfig, Method } from 'axios';
import axios, { AxiosRequestConfig, Method, AxiosError } from 'axios';
import { PricerOptions } from '../../../classes/IPricer';
import log from '../../logger';

export interface PricesTfRequestCheckResponse {
enqueued: boolean;
Expand Down Expand Up @@ -67,11 +68,13 @@ export default class PricesTfApi {
}
);
} catch (e) {
if (e && (e['statusCode'] ? e['statusCode'] : e['status']) === 401) {
const err = e as AxiosError;
if (err.response && err.response.status === 401) {
log.debug('Requesting new token from prices.tf due to 401');
await this.setupToken();
return this.authedApiRequest(httpMethod, path, params, {}, headers);
}
throw e;
throw err;
}
}

Expand Down

0 comments on commit 0a36455

Please sign in to comment.