diff --git a/lib/interceptor/dns.js b/lib/interceptor/dns.js index e0e1d7fa486..457c2af6fa5 100644 --- a/lib/interceptor/dns.js +++ b/lib/interceptor/dns.js @@ -220,37 +220,20 @@ class DNSDispatchHandler extends DecoratorHandler { } onError (err) { - switch (err.code) { - case 'ETIMEDOUT': - case 'ECONNREFUSED': { - if (this.#state.dualStack) { - // We delete the record and retry - this.#state.runLookup(this.#origin, this.#opts, (err, newOrigin) => { - if (err) { - return this.#handler.onError(err) - } - - const dispatchOpts = { - ...this.#opts, - origin: newOrigin - } - - this.#dispatch(dispatchOpts, this) - }) - - // if dual-stack disabled, we error out - return - } + this.#state.deleteRecord(this.#origin) - this.#handler.onError(err) - return - } - case 'ENOTFOUND': - this.#state.deleteRecord(this.#origin) - // eslint-disable-next-line no-fallthrough - default: - this.#handler.onError(err) - break + if (this.#state.dualStack && (err.code === 'ETIMEDOUT' || err.code === 'ECONNREFUSED')) { + // We delete the record and retry + this.#state.runLookup(this.#origin, this.#opts, (err, newOrigin) => { + if (err) { + this.#handler.onError(err) + } else { + // TODO (fix): How to avoid infinite loop? + this.#dispatch({ ...this.#opts, origin: newOrigin }, this) + } + }) + } else { + this.#handler.onError(err) } } }