Useful utilities for working with Fetch
For more features and conveniences on top of Fetch, check out my ky package.
npm install fetch-extras
import {withHttpError, withTimeout} from 'fetch-extras';
// Create an enhanced reusable fetch function that:
// - Throws errors for non-200 responses
// - Times out after 5 seconds
const enhancedFetch = withHttpError(withTimeout(fetch, 5000));
const response = await enhancedFetch('/api');
const data = await response.json();
See the types for now.