Improve auth refreshing to make it work better
This commit is contained in:
parent
7632a7931d
commit
dbd8a486ae
1 changed files with 4 additions and 6 deletions
|
|
@ -8,7 +8,6 @@ export class TwitchAuth {
|
|||
private token_type: string;
|
||||
private scope: string;
|
||||
private expires_in: number;
|
||||
private invalidated: boolean = false;
|
||||
private _bid: string | undefined;
|
||||
|
||||
constructor(token_data: TokenData) {
|
||||
|
|
@ -113,11 +112,7 @@ export class TwitchAuth {
|
|||
* @param conf The Axios RequestConfig, without method, url, or baseURL
|
||||
* @returns The data returned from the Twitch API
|
||||
*/
|
||||
public async request<T>(method: Method, url: string, conf:any={}): Promise<T> {
|
||||
|
||||
if (this.invalidated) {
|
||||
throw new Error("Can't make a request with an invalidated token");
|
||||
};
|
||||
public async request<T>(method: Method, url: string, conf:any={}, attempt=0): Promise<T> {
|
||||
|
||||
try {
|
||||
let headers = {
|
||||
|
|
@ -148,6 +143,9 @@ export class TwitchAuth {
|
|||
switch (err.response.status) {
|
||||
case 403:
|
||||
this.refresh();
|
||||
if (attempt < 3) {
|
||||
this.request(method, url, conf, ++attempt);
|
||||
};
|
||||
break;
|
||||
default:
|
||||
log.error(err);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue