decentraland-dapps 13.52.1 → 13.53.0
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/lib/BaseClient.d.ts
CHANGED
|
@@ -5,11 +5,14 @@ export declare type BaseClientConfig = {
|
|
|
5
5
|
retries?: number;
|
|
6
6
|
/** The delay between retries if the request fails */
|
|
7
7
|
retryDelay?: number;
|
|
8
|
+
/** The status numbers that would not be retried */
|
|
9
|
+
nonRetryableStatuses?: number[];
|
|
8
10
|
};
|
|
9
11
|
export declare abstract class BaseClient {
|
|
10
12
|
private readonly baseUrl;
|
|
11
13
|
private readonly retries;
|
|
12
14
|
private readonly retryDelay;
|
|
15
|
+
private readonly nonRetryableStatuses;
|
|
13
16
|
private readonly identity;
|
|
14
17
|
constructor(url: string, config?: BaseClientConfig);
|
|
15
18
|
private sleep;
|
package/dist/lib/BaseClient.js
CHANGED
|
@@ -38,10 +38,11 @@ const nodeURL = __importStar(require("url"));
|
|
|
38
38
|
const ClientError_1 = require("./ClientError");
|
|
39
39
|
const DEFAULT_RETRIES = 3;
|
|
40
40
|
const DEFAULT_RETRY_DELAY = 1000;
|
|
41
|
+
const DEFAULT_NON_RETRYABLE_STATUSES = [400, 401, 403, 404, 409, 422];
|
|
41
42
|
const URL = (_a = globalThis === null || globalThis === void 0 ? void 0 : globalThis.URL) !== null && _a !== void 0 ? _a : nodeURL.URL;
|
|
42
43
|
class BaseClient {
|
|
43
44
|
constructor(url, config) {
|
|
44
|
-
var _a, _b;
|
|
45
|
+
var _a, _b, _c;
|
|
45
46
|
this.sleep = (delay) => new Promise(resolve => {
|
|
46
47
|
setTimeout(resolve, delay);
|
|
47
48
|
});
|
|
@@ -53,7 +54,7 @@ class BaseClient {
|
|
|
53
54
|
return (0, decentraland_crypto_fetch_1.default)(fullUrl.toString(), Object.assign(Object.assign({}, init), { identity }));
|
|
54
55
|
};
|
|
55
56
|
this.fetch = (path, init) => __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
var
|
|
57
|
+
var _d;
|
|
57
58
|
for (let attempt = 0; attempt <= this.retries; attempt++) {
|
|
58
59
|
try {
|
|
59
60
|
let response;
|
|
@@ -66,7 +67,7 @@ class BaseClient {
|
|
|
66
67
|
throw new ClientError_1.ClientError(error.message, undefined, null);
|
|
67
68
|
}
|
|
68
69
|
if (!response.ok || parsedResponse.ok === false) {
|
|
69
|
-
const errorMessage = (
|
|
70
|
+
const errorMessage = (_d = parsedResponse.message) !== null && _d !== void 0 ? _d : parsedResponse.error;
|
|
70
71
|
throw new ClientError_1.ClientError(errorMessage !== null && errorMessage !== void 0 ? errorMessage : `Request failed with status code ${response.status}`, response.status, parsedResponse.data);
|
|
71
72
|
}
|
|
72
73
|
if (parsedResponse.ok === true) {
|
|
@@ -78,7 +79,7 @@ class BaseClient {
|
|
|
78
79
|
}
|
|
79
80
|
catch (error) {
|
|
80
81
|
console.error(`[API] HTTP request failed: ${error.message || ''}`, error);
|
|
81
|
-
if (this.retries === attempt)
|
|
82
|
+
if (this.retries === attempt || (error.status && this.nonRetryableStatuses.includes(error.status)))
|
|
82
83
|
throw error;
|
|
83
84
|
yield this.sleep(this.retryDelay);
|
|
84
85
|
}
|
|
@@ -89,6 +90,7 @@ class BaseClient {
|
|
|
89
90
|
this.identity = config === null || config === void 0 ? void 0 : config.identity;
|
|
90
91
|
this.retries = (_a = config === null || config === void 0 ? void 0 : config.retries) !== null && _a !== void 0 ? _a : DEFAULT_RETRIES;
|
|
91
92
|
this.retryDelay = (_b = config === null || config === void 0 ? void 0 : config.retryDelay) !== null && _b !== void 0 ? _b : DEFAULT_RETRY_DELAY;
|
|
93
|
+
this.nonRetryableStatuses = (_c = config === null || config === void 0 ? void 0 : config.nonRetryableStatuses) !== null && _c !== void 0 ? _c : DEFAULT_NON_RETRYABLE_STATUSES;
|
|
92
94
|
}
|
|
93
95
|
}
|
|
94
96
|
exports.BaseClient = BaseClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseClient.js","sourceRoot":"","sources":["../../src/lib/BaseClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0FAAkG;AAClG,6CAA8B;AAC9B,+CAA2C;AAE3C,MAAM,eAAe,GAAG,CAAC,CAAA;AACzB,MAAM,mBAAmB,GAAG,IAAI,CAAA;AAChC,MAAM,GAAG,GAAG,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,GAAG,mCAAI,OAAO,CAAC,GAAG,CAAA;
|
|
1
|
+
{"version":3,"file":"BaseClient.js","sourceRoot":"","sources":["../../src/lib/BaseClient.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0FAAkG;AAClG,6CAA8B;AAC9B,+CAA2C;AAE3C,MAAM,eAAe,GAAG,CAAC,CAAA;AACzB,MAAM,mBAAmB,GAAG,IAAI,CAAA;AAChC,MAAM,8BAA8B,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAA;AACrE,MAAM,GAAG,GAAG,MAAA,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,GAAG,mCAAI,OAAO,CAAC,GAAG,CAAA;AAY1C,MAAsB,UAAU;IAU9B,YAAY,GAAW,EAAE,MAAyB;;QAQ1C,UAAK,GAAG,CAAC,KAAa,EAAE,EAAE,CAChC,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE;YACpB,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,CAAA;QAC5B,CAAC,CAAC,CAAA;QAEI,gBAAW,GAAG,GAAG,EAAE,CACzB,IAAI,CAAC,QAAQ,YAAY,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAA;QAE3D,aAAQ,GAAG,CAAC,IAAY,EAAE,IAAwB,EAAqB,EAAE;;YACjF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