Detect Fetch Abort from Service Worker

Viewed 193

Is it possible for an application to specifically receive an "abort" exception if a Service Worker aborts a fetch request?

I'm explicitly aborting fetch requests in a Service Worker, Instead, the application only receives a TypeError, which feels ambiguous and is not specifically indicative of an abort occurring.

Full code: service-worker.js

self.addEventListener('fetch', event => {
  const controller = new AbortController()
  const signal = controller.signal

  event.respondWith(
    fetch(event.request, { signal })
      .catch(e => {}) // prevent uncaught error message in console
      .finally(() => removeAbortController(...))
  )

  // immediately abort the request to exemplify
  controller.abort()
})
0 Answers
Related