Last active
April 28, 2021 06:15
-
-
Save infantiablue/132b0f3144cf767e2a2dbf711cdb3d67 to your computer and use it in GitHub Desktop.
Fetch API Wrapper
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
const callAPI = async (url) => { | |
let response = await fetch(url, { | |
headers: { | |
"Content-Type": "application/json", | |
Accept: "application/json", | |
}, | |
}); | |
if (!response.ok) { | |
const message = `An error has occured: ${response.status}`; | |
throw new Error(message); | |
} | |
return response.json(); | |
}; | |
export default callAPI; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment