Skip to content

Instantly share code, notes, and snippets.

@infojunkie
Last active April 8, 2023 07:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infojunkie/7fab43dbd23f41fec0718c810a313756 to your computer and use it in GitHub Desktop.
Save infojunkie/7fab43dbd23f41fec0718c810a313756 to your computer and use it in GitHub Desktop.
Thinnest wrapper around fetch() Web API to throw an error if not ok
/**
* Fetch wrapper to throw an error if the response is not ok.
* Why indeed? https://github.com/whatwg/fetch/issues/18
*/
export async function fetish(input: RequestInfo | URL, init?: RequestInit | undefined): Promise<Response> {
const response = await fetch(input, init);
if (!response.ok) throw new Error(response.statusText);
return response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment