Skip to content

Instantly share code, notes, and snippets.

@stipsan
Created February 3, 2022 22:36
Show Gist options
  • Save stipsan/23bdb234ac71d3d2bc8351623dcc0dd0 to your computer and use it in GitHub Desktop.
Save stipsan/23bdb234ac71d3d2bc8351623dcc0dd0 to your computer and use it in GitHub Desktop.
What error is thrown when a fetch is aborted?
// Paste in your DevTools console to inspect the error object thrown by fetch
const controller = new AbortController()
fetch(window.location.href, {signal: controller.signal}).catch((err) => {
console.dir(err)
console.assert(err.name === 'AbortError', `${err.name} === 'AbortError'`)
console.assert(err.code === 20, `${err.code} === 20`)
console.assert(
err.message === 'The user aborted a request.',
`${err.message} === 'The user aborted a request.'`
)
console.assert(err instanceof DOMException, `err instanceof DOMException`)
console.assert(err instanceof Error, `err instanceof Error`)
console.assert(
err.toString() === 'AbortError: The user aborted a request.',
`err.toString() === 'AbortError: The user aborted a request.'`
)
console.assert(
Object.prototype.toString.call(err) === '[object DOMException]',
`Object.prototype.toString.call(err) === '[object DOMException]'`
)
})
controller.abort()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment