diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/bun.js/http.exports.js | 61 | 
1 files changed, 33 insertions, 28 deletions
| diff --git a/src/bun.js/http.exports.js b/src/bun.js/http.exports.js index 0e0686961..539f7f8f8 100644 --- a/src/bun.js/http.exports.js +++ b/src/bun.js/http.exports.js @@ -1002,34 +1002,39 @@ export class ClientRequest extends OutgoingMessage {      var method = this.#method,        body = this.#body; -    this.#fetchRequest = fetch( -      `${this.#protocol}//${this.#host}${this.#useDefaultPort ? "" : ":" + this.#port}${this.#path}`, -      { -        method, -        headers: this.getHeaders(), -        body: body && method !== "GET" && method !== "HEAD" && method !== "OPTIONS" ? body : undefined, -        redirect: "manual", -        verbose: Boolean(__DEBUG__), -        signal: this[kAbortController].signal, -      }, -    ) -      .then(response => { -        var res = (this.#res = new IncomingMessage(response, { -          type: "response", -          [kInternalRequest]: this, -        })); -        this.emit("response", res); -      }) -      .catch(err => { -        if (__DEBUG__) globalReportError(err); -        this.emit("error", err); -      }) -      .finally(() => { -        this.#fetchRequest = null; -        this[kClearTimeout](); -      }); - -    callback(); +    try { +      this.#fetchRequest = fetch( +        `${this.#protocol}//${this.#host}${this.#useDefaultPort ? "" : ":" + this.#port}${this.#path}`, +        { +          method, +          headers: this.getHeaders(), +          body: body && method !== "GET" && method !== "HEAD" && method !== "OPTIONS" ? body : undefined, +          redirect: "manual", +          verbose: Boolean(__DEBUG__), +          signal: this[kAbortController].signal, +        }, +      ) +        .then(response => { +          var res = (this.#res = new IncomingMessage(response, { +            type: "response", +            [kInternalRequest]: this, +          })); +          this.emit("response", res); +        }) +        .catch(err => { +          if (__DEBUG__) globalReportError(err); +          this.emit("error", err); +        }) +        .finally(() => { +          this.#fetchRequest = null; +          this[kClearTimeout](); +        }); +    } catch (err) { +      if (__DEBUG__) globalReportError(err); +      this.emit("error", err); +    } finally { +      callback(); +    }    }    get aborted() { | 
