@datocms/rest-client-utils
Advanced tools
Comparing version 0.1.5 to 0.1.8
@@ -147,3 +147,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var requestId, preCallStack, userAgent, retryCount, logLevel, autoRetry, log, headers, baseUrl, body, queryString, url, _a, _b, _c, key, value, response_1, waitTimeInSecs, responseBody, _d, jobResult, error, error_1; | ||
var requestId, preCallStack, userAgent, retryCount, logLevel, autoRetry, log, headers, baseUrl, body, queryString, url, _a, _b, _c, key, value, response_1, responseContentType, invalidContentType, waitTimeInSecs, responseBody, _d, jobResult, error, error_1; | ||
var e_1, _e; | ||
@@ -199,4 +199,6 @@ return __generator(this, function (_f) { | ||
response_1 = _f.sent(); | ||
if (!(response_1.status === 429)) return [3 /*break*/, 4]; | ||
if (!autoRetry) { | ||
responseContentType = response_1.headers.get('Content-Type'); | ||
invalidContentType = responseContentType && !responseContentType.includes('application/json'); | ||
if (!(response_1.status === 429 || invalidContentType)) return [3 /*break*/, 4]; | ||
if (!autoRetry || (invalidContentType && options.method !== 'GET')) { | ||
throw new ApiError_1.ApiError(buildApiErrorInitObject(options.method, url, headers, options.body, response_1, undefined, preCallStack)); | ||
@@ -209,3 +211,8 @@ } | ||
if (logLevel >= LogLevel.BASIC) { | ||
log("[".concat(requestId, "] Rate limit exceeded, waiting ").concat(waitTimeInSecs, " seconds...")); | ||
if (response_1.status === 429) { | ||
log("[".concat(requestId, "] Rate limit exceeded, wait ").concat(waitTimeInSecs, " seconds then retry...")); | ||
} | ||
else { | ||
log("[".concat(requestId, "] Invalid response content type \"").concat(responseContentType, "\" (status ").concat(response_1.status, "). Wait ").concat(waitTimeInSecs, " seconds then retry...")); | ||
} | ||
} | ||
@@ -221,3 +228,2 @@ return [4 /*yield*/, wait(waitTimeInSecs * 1000)]; | ||
[ | ||
'content-type', | ||
'x-api-version', | ||
@@ -264,3 +270,3 @@ 'x-environment', | ||
if (logLevel >= LogLevel.BASIC) { | ||
log("[".concat(requestId, "] Data validation in progress, waiting ").concat(retryCount, " seconds...")); | ||
log("[".concat(requestId, "] Data validation in progress, wait ").concat(retryCount, " seconds then retry...")); | ||
} | ||
@@ -276,3 +282,3 @@ return [4 /*yield*/, wait(retryCount * 1000)]; | ||
if (logLevel >= LogLevel.BASIC) { | ||
log("[".concat(requestId, "] Error ").concat(error_1.code, ", waiting ").concat(retryCount, " seconds...")); | ||
log("[".concat(requestId, "] Error ").concat(error_1.code, ", wait ").concat(retryCount, " seconds then retry...")); | ||
} | ||
@@ -279,0 +285,0 @@ return [4 /*yield*/, wait(retryCount * 1000)]; |
@@ -141,3 +141,3 @@ var __assign = (this && this.__assign) || function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var requestId, preCallStack, userAgent, retryCount, logLevel, autoRetry, log, headers, baseUrl, body, queryString, url, _a, _b, _c, key, value, response_1, waitTimeInSecs, responseBody, _d, jobResult, error, error_1; | ||
var requestId, preCallStack, userAgent, retryCount, logLevel, autoRetry, log, headers, baseUrl, body, queryString, url, _a, _b, _c, key, value, response_1, responseContentType, invalidContentType, waitTimeInSecs, responseBody, _d, jobResult, error, error_1; | ||
var e_1, _e; | ||
@@ -193,4 +193,6 @@ return __generator(this, function (_f) { | ||
response_1 = _f.sent(); | ||
if (!(response_1.status === 429)) return [3 /*break*/, 4]; | ||
if (!autoRetry) { | ||
responseContentType = response_1.headers.get('Content-Type'); | ||
invalidContentType = responseContentType && !responseContentType.includes('application/json'); | ||
if (!(response_1.status === 429 || invalidContentType)) return [3 /*break*/, 4]; | ||
if (!autoRetry || (invalidContentType && options.method !== 'GET')) { | ||
throw new ApiError(buildApiErrorInitObject(options.method, url, headers, options.body, response_1, undefined, preCallStack)); | ||
@@ -203,3 +205,8 @@ } | ||
if (logLevel >= LogLevel.BASIC) { | ||
log("[".concat(requestId, "] Rate limit exceeded, waiting ").concat(waitTimeInSecs, " seconds...")); | ||
if (response_1.status === 429) { | ||
log("[".concat(requestId, "] Rate limit exceeded, wait ").concat(waitTimeInSecs, " seconds then retry...")); | ||
} | ||
else { | ||
log("[".concat(requestId, "] Invalid response content type \"").concat(responseContentType, "\" (status ").concat(response_1.status, "). Wait ").concat(waitTimeInSecs, " seconds then retry...")); | ||
} | ||
} | ||
@@ -215,3 +222,2 @@ return [4 /*yield*/, wait(waitTimeInSecs * 1000)]; | ||
[ | ||
'content-type', | ||
'x-api-version', | ||
@@ -258,3 +264,3 @@ 'x-environment', | ||
if (logLevel >= LogLevel.BASIC) { | ||
log("[".concat(requestId, "] Data validation in progress, waiting ").concat(retryCount, " seconds...")); | ||
log("[".concat(requestId, "] Data validation in progress, wait ").concat(retryCount, " seconds then retry...")); | ||
} | ||
@@ -270,3 +276,3 @@ return [4 /*yield*/, wait(retryCount * 1000)]; | ||
if (logLevel >= LogLevel.BASIC) { | ||
log("[".concat(requestId, "] Error ").concat(error_1.code, ", waiting ").concat(retryCount, " seconds...")); | ||
log("[".concat(requestId, "] Error ").concat(error_1.code, ", wait ").concat(retryCount, " seconds then retry...")); | ||
} | ||
@@ -273,0 +279,0 @@ return [4 /*yield*/, wait(retryCount * 1000)]; |
{ | ||
"name": "@datocms/rest-client-utils", | ||
"version": "0.1.5", | ||
"version": "0.1.8", | ||
"description": "Utilities for DatoCMS REST API clients", | ||
@@ -43,3 +43,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "dc93ff1a234e3e95a1db409b44c3fe538afd8a1e" | ||
"gitHead": "ffb2f67a843f695e97dd14e2ca493f9dc9c87823" | ||
} |
@@ -156,4 +156,8 @@ import qs from 'qs'; | ||
if (response.status === 429) { | ||
if (!autoRetry) { | ||
const responseContentType = response.headers.get('Content-Type'); | ||
const invalidContentType = | ||
responseContentType && !responseContentType.includes('application/json'); | ||
if (response.status === 429 || invalidContentType) { | ||
if (!autoRetry || (invalidContentType && options.method !== 'GET')) { | ||
throw new ApiError( | ||
@@ -178,5 +182,11 @@ buildApiErrorInitObject( | ||
if (logLevel >= LogLevel.BASIC) { | ||
log( | ||
`[${requestId}] Rate limit exceeded, waiting ${waitTimeInSecs} seconds...`, | ||
); | ||
if (response.status === 429) { | ||
log( | ||
`[${requestId}] Rate limit exceeded, wait ${waitTimeInSecs} seconds then retry...`, | ||
); | ||
} else { | ||
log( | ||
`[${requestId}] Invalid response content type "${responseContentType}" (status ${response.status}). Wait ${waitTimeInSecs} seconds then retry...`, | ||
); | ||
} | ||
} | ||
@@ -193,3 +203,2 @@ | ||
[ | ||
'content-type', | ||
'x-api-version', | ||
@@ -255,3 +264,3 @@ 'x-environment', | ||
log( | ||
`[${requestId}] Data validation in progress, waiting ${retryCount} seconds...`, | ||
`[${requestId}] Data validation in progress, wait ${retryCount} seconds then retry...`, | ||
); | ||
@@ -270,3 +279,3 @@ } | ||
log( | ||
`[${requestId}] Error ${error.code}, waiting ${retryCount} seconds...`, | ||
`[${requestId}] Error ${error.code}, wait ${retryCount} seconds then retry...`, | ||
); | ||
@@ -273,0 +282,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
163504
2861