@snyk/docker-registry-v2-client
Advanced tools
Comparing version 2.2.4 to 2.3.0
@@ -13,4 +13,4 @@ import { NeedleOptions, NeedleResponse } from "needle"; | ||
*/ | ||
export declare function needleWrapper(options: RequestOptions): Promise<NeedleResponse>; | ||
export declare function needleWrapper(options: RequestOptions, maxRetries?: number): Promise<NeedleResponse>; | ||
export declare function parseResponseBody(response: NeedleResponse): any; | ||
export {}; |
@@ -22,3 +22,3 @@ "use strict"; | ||
*/ | ||
async function needleWrapper(options) { | ||
async function needleWrapper(options, maxRetries) { | ||
var _a, _b; | ||
@@ -37,3 +37,17 @@ let uri = options.uri; | ||
} | ||
const response = await needle("get", uri, options); | ||
let response; | ||
let lastError; | ||
let retries = maxRetries !== null && maxRetries !== void 0 ? maxRetries : 0; | ||
while (!response && retries >= 0) { | ||
retries--; | ||
try { | ||
response = await needle("get", uri, options); | ||
} | ||
catch (err) { | ||
lastError = err; | ||
} | ||
} | ||
if (!response) { | ||
throw lastError; | ||
} | ||
// throw an error in case status code is not 2xx | ||
@@ -40,0 +54,0 @@ if (response && response.statusCode >= 300) { |
@@ -8,6 +8,7 @@ "use strict"; | ||
const BEARER_REALM = "Bearer realm"; | ||
const MAX_RETRIES = 1; | ||
async function registryV2Call(registryBase, endpoint, accept, username, password, reqOptions = {}) { | ||
const reqConfig = buildUnauthenticatedV2RequestConfig(registryBase, endpoint, accept, reqOptions); | ||
try { | ||
return await needle_1.needleWrapper(reqConfig); | ||
return await needle_1.needleWrapper(reqConfig, MAX_RETRIES); | ||
} | ||
@@ -24,3 +25,3 @@ catch (err) { | ||
try { | ||
return await needle_1.needleWrapper(authConfig); | ||
return await needle_1.needleWrapper(authConfig, MAX_RETRIES); | ||
} | ||
@@ -132,3 +133,3 @@ catch (err) { | ||
config.uri = redirectUrl; | ||
return await needle_1.needleWrapper(config); | ||
return await needle_1.needleWrapper(config, MAX_RETRIES); | ||
} | ||
@@ -135,0 +136,0 @@ /* |
@@ -45,3 +45,3 @@ { | ||
}, | ||
"version": "2.2.4" | ||
"version": "2.3.0" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
47805
591