Skip to content

Instantly share code, notes, and snippets.

@sibelius
Created April 15, 2021 18:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sibelius/1d81c162571b3861fd5c3473e36ddb81 to your computer and use it in GitHub Desktop.
Save sibelius/1d81c162571b3861fd5c3473e36ddb81 to your computer and use it in GitHub Desktop.
get a text or json from a fetch response
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