fetchWithNetworkError.js 386 B

12345678910111213141516171819
  1. "use strict";
  2. const NetworkError = require("./NetworkError.js");
  3. /**
  4. * Wrapper around window.fetch that throws a NetworkError when appropriate
  5. */
  6. function fetchWithNetworkError() {
  7. return fetch(...arguments).catch(err => {
  8. if (err.name === 'AbortError') {
  9. throw err;
  10. } else {
  11. throw new NetworkError(err);
  12. }
  13. });
  14. }
  15. module.exports = fetchWithNetworkError;