@google-cloud/common
Advanced tools
Comparing version 3.6.0 to 3.7.0
@@ -58,3 +58,4 @@ "use strict"; | ||
}); | ||
this.makeAuthenticatedRequest = util_1.util.makeAuthenticatedRequestFactory(reqCfg); | ||
this.makeAuthenticatedRequest = | ||
util_1.util.makeAuthenticatedRequestFactory(reqCfg); | ||
this.authClient = this.makeAuthenticatedRequest.authClient; | ||
@@ -61,0 +62,0 @@ this.getCredentials = this.makeAuthenticatedRequest.getCredentials; |
@@ -154,2 +154,10 @@ /// <reference types="node" /> | ||
} | ||
export interface RetryOptions { | ||
retryDelayMultiplier?: number; | ||
totalTimeout?: number; | ||
maxRetryDelay?: number; | ||
autoRetry?: boolean; | ||
maxRetries?: number; | ||
retryableErrorFn?: (err: ApiError) => boolean; | ||
} | ||
export interface MakeRequestConfig { | ||
@@ -168,2 +176,3 @@ /** | ||
retries?: number; | ||
retryOptions?: RetryOptions; | ||
stream?: Duplexify; | ||
@@ -170,0 +179,0 @@ shouldRetryFn?: (response?: r.Response) => boolean; |
@@ -37,2 +37,16 @@ "use strict"; | ||
/** | ||
* Default behavior: Automatically retry retriable server errors. | ||
* | ||
* @const {boolean} | ||
* @private | ||
*/ | ||
const AUTO_RETRY_DEFAULT = true; | ||
/** | ||
* Default behavior: Only attempt to retry retriable errors 3 times. | ||
* | ||
* @const {number} | ||
* @private | ||
*/ | ||
const MAX_RETRY_DEFAULT = 3; | ||
/** | ||
* Custom error type for API errors. | ||
@@ -422,9 +436,38 @@ * | ||
makeRequest(reqOpts, config, callback) { | ||
var _a, _b, _c, _d, _e, _f, _g; | ||
let autoRetryValue = AUTO_RETRY_DEFAULT; | ||
if (config.autoRetry !== undefined && | ||
((_a = config.retryOptions) === null || _a === void 0 ? void 0 : _a.autoRetry) !== undefined) { | ||
throw new ApiError('autoRetry is deprecated. Use retryOptions.autoRetry instead.'); | ||
} | ||
else if (config.autoRetry !== undefined) { | ||
autoRetryValue = config.autoRetry; | ||
} | ||
else if (((_b = config.retryOptions) === null || _b === void 0 ? void 0 : _b.autoRetry) !== undefined) { | ||
autoRetryValue = config.retryOptions.autoRetry; | ||
} | ||
let maxRetryValue = MAX_RETRY_DEFAULT; | ||
if (config.maxRetries && ((_c = config.retryOptions) === null || _c === void 0 ? void 0 : _c.maxRetries)) { | ||
throw new ApiError('maxRetries is deprecated. Use retryOptions.maxRetries instead.'); | ||
} | ||
else if (config.maxRetries) { | ||
maxRetryValue = config.maxRetries; | ||
} | ||
else if ((_d = config.retryOptions) === null || _d === void 0 ? void 0 : _d.maxRetries) { | ||
maxRetryValue = config.retryOptions.maxRetries; | ||
} | ||
const options = { | ||
request: teeny_request_1.teenyRequest.defaults(requestDefaults), | ||
retries: config.autoRetry !== false ? config.maxRetries || 3 : 0, | ||
retries: autoRetryValue !== false ? maxRetryValue : 0, | ||
shouldRetryFn(httpRespMessage) { | ||
var _a, _b; | ||
const err = util.parseHttpRespMessage(httpRespMessage).err; | ||
if ((_a = config.retryOptions) === null || _a === void 0 ? void 0 : _a.retryableErrorFn) { | ||
return err && ((_b = config.retryOptions) === null || _b === void 0 ? void 0 : _b.retryableErrorFn(err)); | ||
} | ||
return err && util.shouldRetryRequest(err); | ||
}, | ||
maxRetryDelay: (_e = config.retryOptions) === null || _e === void 0 ? void 0 : _e.maxRetryDelay, | ||
retryDelayMultiplier: (_f = config.retryOptions) === null || _f === void 0 ? void 0 : _f.retryDelayMultiplier, | ||
totalTimeout: (_g = config.retryOptions) === null || _g === void 0 ? void 0 : _g.totalTimeout, | ||
}; | ||
@@ -431,0 +474,0 @@ if (typeof reqOpts.maxRetries === 'number') { |
@@ -7,2 +7,9 @@ # Changelog | ||
## [3.7.0](https://www.github.com/googleapis/nodejs-common/compare/v3.6.0...v3.7.0) (2021-07-09) | ||
### Features | ||
* Customize retry implementation ([#680](https://www.github.com/googleapis/nodejs-common/issues/680)) ([b529998](https://www.github.com/googleapis/nodejs-common/commit/b529998cdd1c8a7f159846f65651e2118bae5d9e)) | ||
## [3.6.0](https://www.github.com/googleapis/nodejs-common/compare/v3.5.0...v3.6.0) (2021-02-17) | ||
@@ -9,0 +16,0 @@ |
{ | ||
"name": "@google-cloud/common", | ||
"description": "Common components for Cloud APIs Node.js Client Libraries", | ||
"version": "3.6.0", | ||
"version": "3.7.0", | ||
"license": "Apache-2.0", | ||
@@ -32,5 +32,3 @@ "author": "Google Inc.", | ||
"clean": "gts clean", | ||
"precompile": "gts clean", | ||
"api-extractor": "api-extractor run --local", | ||
"api-documenter": "api-documenter yaml --input-folder=temp" | ||
"precompile": "gts clean" | ||
}, | ||
@@ -45,3 +43,3 @@ "dependencies": { | ||
"google-auth-library": "^7.0.2", | ||
"retry-request": "^4.1.1", | ||
"retry-request": "^4.2.2", | ||
"teeny-request": "^7.0.0" | ||
@@ -51,4 +49,2 @@ }, | ||
"@compodoc/compodoc": "^1.1.11", | ||
"@microsoft/api-documenter": "^7.8.10", | ||
"@microsoft/api-extractor": "^7.8.10", | ||
"@types/ent": "^2.2.1", | ||
@@ -59,7 +55,7 @@ "@types/extend": "^3.0.1", | ||
"@types/ncp": "^2.0.3", | ||
"@types/node": "^12.12.31", | ||
"@types/node": "^14.0.0", | ||
"@types/proxyquire": "^1.3.28", | ||
"@types/request": "^2.48.4", | ||
"@types/sinon": "^9.0.0", | ||
"@types/tmp": "0.2.0", | ||
"@types/sinon": "^10.0.0", | ||
"@types/tmp": "0.2.1", | ||
"c8": "^7.1.0", | ||
@@ -74,3 +70,3 @@ "codecov": "^3.6.5", | ||
"proxyquire": "^2.1.3", | ||
"sinon": "^9.0.1", | ||
"sinon": "^11.0.0", | ||
"tmp": "0.2.1", | ||
@@ -77,0 +73,0 @@ "typescript": "~3.8.3" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
122671
23
1904
Updatedretry-request@^4.2.2