MCPcopy Create free account
hub / github.com/angular/dev-infra / onHeaders

Method onHeaders

github-actions/saucelabs/set-saucelabs-env.js:9424–9530  ·  view source on GitHub ↗
(statusCode, rawHeaders, resume, statusMessage)

Source from the content-addressed store, hash-verified

9422 const { statusCode, code, headers } = err;
9423 const { method, retryOptions } = opts;
9424 const {
9425 maxRetries,
9426 minTimeout,
9427 maxTimeout,
9428 timeoutFactor,
9429 statusCodes,
9430 errorCodes,
9431 methods
9432 } = retryOptions;
9433 const { counter } = state;
9434 if (code && code !== "UND_ERR_REQ_RETRY" && !errorCodes.includes(code)) {
9435 cb(err);
9436 return;
9437 }
9438 if (Array.isArray(methods) && !methods.includes(method)) {
9439 cb(err);
9440 return;
9441 }
9442 if (statusCode != null && Array.isArray(statusCodes) && !statusCodes.includes(statusCode)) {
9443 cb(err);
9444 return;
9445 }
9446 if (counter > maxRetries) {
9447 cb(err);
9448 return;
9449 }
9450 let retryAfterHeader = headers == null ? void 0 : headers["retry-after"];
9451 if (retryAfterHeader) {
9452 retryAfterHeader = Number(retryAfterHeader);
9453 retryAfterHeader = Number.isNaN(retryAfterHeader) ? calculateRetryAfterHeader(retryAfterHeader) : retryAfterHeader * 1e3;
9454 }
9455 const retryTimeout = retryAfterHeader > 0 ? Math.min(retryAfterHeader, maxTimeout) : Math.min(minTimeout * __pow(timeoutFactor, counter - 1), maxTimeout);
9456 setTimeout(() => cb(null), retryTimeout);
9457 }
9458 onHeaders(statusCode, rawHeaders, resume, statusMessage) {
9459 const headers = parseHeaders(rawHeaders);
9460 this.retryCount += 1;
9461 if (statusCode >= 300) {
9462 if (this.retryOpts.statusCodes.includes(statusCode) === false) {
9463 return this.handler.onHeaders(
9464 statusCode,
9465 rawHeaders,
9466 resume,
9467 statusMessage
9468 );
9469 } else {
9470 this.abort(
9471 new RequestRetryError("Request failed", statusCode, {
9472 headers,
9473 data: {
9474 count: this.retryCount
9475 }
9476 })
9477 );
9478 return false;
9479 }
9480 }
9481 if (this.resume != null) {

Callers

nothing calls this directly

Calls 4

parseHeadersFunction · 0.70
parseRangeHeaderFunction · 0.70
onHeadersMethod · 0.45
abortMethod · 0.45

Tested by

no test coverage detected