Better debugging output on fetch errors.

This commit is contained in:
Richard Moore 2024-01-15 13:43:56 -05:00
parent 2f36f59d76
commit bee07a0750

@ -936,8 +936,20 @@ export class FetchResponse implements Iterable<[ key: string, value: string ]> {
if (message === "") {
message = `server response ${ this.statusCode } ${ this.statusMessage }`;
}
let requestUrl: null | string = null;
if (this.request) { requestUrl = this.request.url; }
let responseBody: null | string = null;
try {
if (this.#body) { responseBody = toUtf8String(this.#body); }
} catch (e) { }
assert(false, message, "SERVER_ERROR", {
request: (this.request || "unknown request"), response: this, error
request: (this.request || "unknown request"), response: this, error,
info: {
requestUrl, responseBody,
responseStatus: `${ this.statusCode } ${ this.statusMessage }` }
});
}
}