mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-08-30 14:48:19 -05:00
Use cached web service token to renew SplatNet 3 tokens and fix retrying getting web service tokens after renewing coral token
This commit is contained in:
@@ -224,6 +224,7 @@ export default class CoralApi {
|
||||
return await this.call<WebServiceToken>('/v2/Game/GetWebServiceToken', req, false);
|
||||
} catch (err) {
|
||||
if (err instanceof ErrorResponse && err.data.status === CoralStatus.TOKEN_EXPIRED && !_attempt && this.onTokenExpired) {
|
||||
debug('Error getting web service token, renewing token before retrying', err);
|
||||
// _renewToken will be awaited when calling getWebServiceToken
|
||||
this._renewToken = this._renewToken ?? this.onTokenExpired.call(null, err.data, err.response as Response).then(data => {
|
||||
if (data) this.setTokenWithSavedToken(data);
|
||||
|
||||
@@ -2,6 +2,7 @@ import * as util from 'node:util';
|
||||
import { Response as NodeFetchResponse } from 'node-fetch';
|
||||
|
||||
export const ResponseSymbol = Symbol('Response');
|
||||
const ErrorResponseSymbol = Symbol('IsErrorResponse');
|
||||
|
||||
export interface ResponseData<R> {
|
||||
[ResponseSymbol]: R;
|
||||
@@ -24,6 +25,8 @@ export class ErrorResponse<T = unknown> extends Error {
|
||||
) {
|
||||
super(message);
|
||||
|
||||
Object.defineProperty(this, ErrorResponseSymbol, {enumerable: false, value: ErrorResponseSymbol});
|
||||
|
||||
if (typeof body === 'string') {
|
||||
this.body = body;
|
||||
try {
|
||||
@@ -51,9 +54,6 @@ export class ErrorResponse<T = unknown> extends Error {
|
||||
Object.defineProperty(ErrorResponse, Symbol.hasInstance, {
|
||||
configurable: true,
|
||||
value: (instance: ErrorResponse) => {
|
||||
return instance instanceof Error &&
|
||||
'response' in instance &&
|
||||
'body' in instance &&
|
||||
'data' in instance;
|
||||
return instance && ErrorResponseSymbol in instance;
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user