Created
April 15, 2021 18:10
-
-
Save sibelius/1d81c162571b3861fd5c3473e36ddb81 to your computer and use it in GitHub Desktop.
get a text or json from a fetch response
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
export const jsonOrText = async (response: Response) => { | |
const text = await response.text(); | |
try { | |
return JSON.parse(text); | |
} catch (err) { | |
return text; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment