Last active
April 8, 2023 07:17
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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