Skip to content

Instantly share code, notes, and snippets.

@inodaf
Last active June 24, 2020 19:57
Show Gist options
  • Save inodaf/e5f8756075f609015462b9505772e052 to your computer and use it in GitHub Desktop.
Save inodaf/e5f8756075f609015462b9505772e052 to your computer and use it in GitHub Desktop.
πŸ– Pending Responses for Fetch API.

Awaits for a pending response with a single line.

const { status, data, error } = await parseResponse(fetch('/resource')))
export async function parseResponse(pending: Response) {
try {
const response = await pending
return { ...response }
} catch (error) {
return { ...error.response, error }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment