Created
February 3, 2022 22:36
-
-
Save stipsan/23bdb234ac71d3d2bc8351623dcc0dd0 to your computer and use it in GitHub Desktop.
What error is thrown when a fetch is aborted?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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