@straw-hat/fetcher
Version:
Simple HTTP Client
32 lines • 960 B
JavaScript
import { getResponseBody } from './helpers.js';
export class FetcherError extends Error {
statusText;
status;
body;
url;
constructor(args) {
super();
// Set the prototype explicitly.
Object.setPrototypeOf(this, FetcherError.prototype);
// @ts-ignore TS doesn't know about captureStackTrace
Error.captureStackTrace?.(this, FetcherError);
this.name = 'FetcherError';
this.status = args.status;
this.statusText = args.statusText;
this.body = args.body;
this.url = args.url;
}
get message() {
return `${this.status} ${this.statusText} ${this.url}`;
}
}
export async function errorFromResponse(response) {
const body = await getResponseBody(response);
return new FetcherError({
body,
statusText: response.statusText,
status: response.status,
url: response.url,
});
}
//# sourceMappingURL=errors.js.map