guildwars2-ts 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +12 -16
- package/dist/index.d.ts +12 -16
- package/dist/index.js +34 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +34 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -5
package/dist/index.mjs
CHANGED
|
@@ -107,8 +107,6 @@ var ApiBase = class {
|
|
|
107
107
|
}
|
|
108
108
|
/**
|
|
109
109
|
* Parameters for the api response, at top level
|
|
110
|
-
*
|
|
111
|
-
* @returns Api parameters
|
|
112
110
|
*/
|
|
113
111
|
getParams() {
|
|
114
112
|
return {
|
|
@@ -156,46 +154,62 @@ var ApiBase = class {
|
|
|
156
154
|
}
|
|
157
155
|
return data;
|
|
158
156
|
} catch (error) {
|
|
159
|
-
return await this.retryRequest(endpoint, options, responseType, apiParams, error);
|
|
157
|
+
return await this.retryRequest(endpoint, options, responseType, apiParams, 0, error);
|
|
160
158
|
}
|
|
161
159
|
}
|
|
162
160
|
/**
|
|
163
161
|
* Retries failed requests
|
|
164
|
-
* TODO: Fix logic. Rate-limits are almost impossible hit, but other generic requests will fail and loop forever
|
|
165
162
|
*
|
|
166
163
|
* @param endpoint - Endpoint to which a request was originally made
|
|
167
164
|
* @param prevOptions - Axios request options
|
|
168
165
|
* @param responseType - Originally requested schema
|
|
169
166
|
* @param apiParams - Query string
|
|
167
|
+
* @param rateLimitAttempt - Current rate-limit retry counter
|
|
170
168
|
* @param prevError - Error that caused a retry
|
|
171
|
-
* @returns Successful request, or error
|
|
172
169
|
*/
|
|
173
|
-
async retryRequest(endpoint, prevOptions, responseType, apiParams, prevError) {
|
|
174
|
-
if (prevError instanceof AxiosError) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
170
|
+
async retryRequest(endpoint, prevOptions, responseType, apiParams, rateLimitAttempt = 0, prevError) {
|
|
171
|
+
if (prevError instanceof AxiosError && prevError.response) {
|
|
172
|
+
const { status } = prevError.response;
|
|
173
|
+
switch (true) {
|
|
174
|
+
case status === 401: {
|
|
178
175
|
logger.warn(`Request to ${prevOptions.url} failed.`);
|
|
179
176
|
throw new ApiTokenError();
|
|
180
177
|
}
|
|
181
|
-
|
|
178
|
+
case status === 403: {
|
|
182
179
|
const requiredScope = prevError.response.data.text.slice(0, 1).toUpperCase() + prevError.response.data.text.slice(1);
|
|
183
180
|
logger.warn(`Request to ${prevOptions.url} failed. ${requiredScope}.`);
|
|
184
181
|
throw new ApiPermissionsError(requiredScope);
|
|
185
182
|
}
|
|
186
|
-
|
|
183
|
+
case status === 404: {
|
|
187
184
|
logger.warn(`Request to ${prevOptions.url} returned no data.`);
|
|
188
185
|
throw new ApiNotFoundError();
|
|
189
186
|
}
|
|
190
|
-
|
|
187
|
+
case (status === 429 && this._rateLimitRetry): {
|
|
188
|
+
logger.warn("Rate-limit has been reached. Request will be repeated soon.");
|
|
189
|
+
if (rateLimitAttempt < 3) {
|
|
190
|
+
setTimeout(async () => {
|
|
191
|
+
return await this.retryRequest(
|
|
192
|
+
endpoint,
|
|
193
|
+
prevOptions,
|
|
194
|
+
responseType,
|
|
195
|
+
apiParams,
|
|
196
|
+
rateLimitAttempt++,
|
|
197
|
+
prevError
|
|
198
|
+
);
|
|
199
|
+
}, 1e3);
|
|
200
|
+
break;
|
|
201
|
+
} else {
|
|
202
|
+
logger.error(`Rate-limit retries failed. Aborting request to ${prevOptions.url}`);
|
|
203
|
+
throw new ApiRetryFailedError();
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
case status === 504: {
|
|
191
207
|
logger.warn(`Request to ${prevOptions.url} timed out.`);
|
|
192
208
|
throw new ApiTimeoutError();
|
|
193
209
|
}
|
|
210
|
+
default:
|
|
211
|
+
logger.warn(`Request to ${prevOptions.url} failed. ${prevError.message}`);
|
|
194
212
|
}
|
|
195
|
-
logger.warn(`Request to ${prevOptions.url} failed. ${prevError.message}`);
|
|
196
|
-
} else if (this._rateLimitRetry) {
|
|
197
|
-
logger.info(`Rate-limit retries failed. Aborting request to ${prevOptions.url}`);
|
|
198
|
-
throw new ApiRetryFailedError();
|
|
199
213
|
}
|
|
200
214
|
throw new ApiGenericError();
|
|
201
215
|
}
|
|
@@ -204,7 +218,6 @@ var ApiBase = class {
|
|
|
204
218
|
*
|
|
205
219
|
* @param endpoint - Api endpoint
|
|
206
220
|
* @param urlParams - Parameters
|
|
207
|
-
* @returns Finalized endpoint Url
|
|
208
221
|
*/
|
|
209
222
|
_getApiUrl(endpoint, urlParams) {
|
|
210
223
|
const { path } = endpoint;
|
|
@@ -1543,9 +1556,9 @@ var GuildTeamsDTO = z.array(
|
|
|
1543
1556
|
/** Team ladder statistics aggregates. */
|
|
1544
1557
|
ladders: z.object({
|
|
1545
1558
|
/** Ranked arena stats. */
|
|
1546
|
-
ranked: PvPAggregate,
|
|
1559
|
+
ranked: PvPAggregate.optional(),
|
|
1547
1560
|
/** Unranked arena stats. */
|
|
1548
|
-
unranked: PvPAggregate
|
|
1561
|
+
unranked: PvPAggregate.optional()
|
|
1549
1562
|
}),
|
|
1550
1563
|
/** Team games. */
|
|
1551
1564
|
games: z.array(PvPGame),
|
|
@@ -1561,7 +1574,7 @@ var GuildTeamsDTO = z.array(
|
|
|
1561
1574
|
/** Seasonal rating. */
|
|
1562
1575
|
rating: z.number()
|
|
1563
1576
|
})
|
|
1564
|
-
)
|
|
1577
|
+
).optional()
|
|
1565
1578
|
})
|
|
1566
1579
|
);
|
|
1567
1580
|
var GuildTreasuryDTO = z.array(
|