index.d.ts 617 B

1234567891011121314151617181920212223242526
  1. /**
  2. Check if an error is a [Fetch network error](https://developer.mozilla.org/en-US/docs/Web/API/fetch#exceptions)
  3. @return Returns `true` if the given value is a Fetch network error, otherwise `false`.
  4. @example
  5. ```
  6. import isNetworkError from 'is-network-error';
  7. async function getUnicorns() {
  8. try {
  9. const response = await fetch('unicorns.json');
  10. return await response.json();
  11. } catch (error) {
  12. if (isNetworkError(error)) {
  13. return localStorage.getItem('…');
  14. }
  15. throw error;
  16. }
  17. }
  18. console.log(await getUnicorns());
  19. ```
  20. */
  21. export default function isNetworkError(value: unknown): value is TypeError;