MCPcopy Create free account
hub / github.com/nodejs/node / onResponseError

Method onResponseError

deps/undici/src/lib/interceptor/dns.js:404–455  ·  view source on GitHub ↗
(controller, err)

Source from the content-addressed store, hash-verified

402 }
403
404 onResponseError (controller, err) {
405 switch (err.code) {
406 case 'ETIMEDOUT':
407 case 'ECONNREFUSED': {
408 if (this.#state.dualStack) {
409 if (!this.#firstTry) {
410 super.onResponseError(controller, err)
411 return
412 }
413 this.#firstTry = false
414
415 // Pick an ip address from the other family
416 const otherFamily = this.#newOrigin.hostname[0] === '[' ? 4 : 6
417 const ip = this.#state.pickFamily(this.#origin, otherFamily)
418 if (ip == null) {
419 super.onResponseError(controller, err)
420 return
421 }
422
423 let port
424 if (typeof ip.port === 'number') {
425 port = `:${ip.port}`
426 } else if (this.#origin.port !== '') {
427 port = `:${this.#origin.port}`
428 } else {
429 port = ''
430 }
431
432 const dispatchOpts = {
433 ...this.#opts,
434 origin: `${this.#origin.protocol}//${
435 ip.family === 6 ? `[${ip.address}]` : ip.address
436 }${port}`,
437 headers: withHostHeader(this.#origin.host, this.#opts.headers)
438 }
439 this.#dispatch(dispatchOpts, this)
440 return
441 }
442
443 // if dual-stack disabled, we error out
444 super.onResponseError(controller, err)
445 break
446 }
447 case 'ENOTFOUND':
448 this.#state.deleteRecords(this.#origin)
449 super.onResponseError(controller, err)
450 break
451 default:
452 super.onResponseError(controller, err)
453 break
454 }
455 }
456}
457
458module.exports = interceptorOpts => {

Callers

nothing calls this directly

Calls 4

withHostHeaderFunction · 0.85
pickFamilyMethod · 0.80
deleteRecordsMethod · 0.80
onResponseErrorMethod · 0.65

Tested by

no test coverage detected