Skip to content

Commit

Permalink
Better debugging output on fetch errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Jan 15, 2024
1 parent 2f36f59 commit bee07a0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src.ts/utils/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }` }
});
}
}
Expand Down

0 comments on commit bee07a0

Please sign in to comment.