sindresorhus / ky

🌳 Tiny & elegant JavaScript HTTP client based on the Fetch API
MIT License
13.46k stars 361 forks source link

Consider extracting the HTTPError logic to an external module #609

Closed fregante closed 1 month ago

fregante commented 1 month ago

I mentioned this in private before, but I think it might be beneficial to create a package with an API like:

const response = fetch('/api');
if (!response.ok) 
    throw HTTPError.from(response);
const response = fetch('/api');
throwIfHttpError(response);
sindresorhus commented 1 month ago

Yeah, I have an already almost finished package for this.

sholladay commented 1 month ago

boom has a lot of nice features, although it is optimized for server-side usage: https://github.com/hapijs/boom

sindresorhus commented 1 month ago

@fregante https://github.com/sindresorhus/fetch-extras

Feedback welcome :)

fregante commented 1 month ago

Good idea to make a single utilities package, there might be more ☺️