fix(nuxt): pass DOMException as fetch abort exception (#29058)

This commit is contained in:
DarkVen0m 2024-09-18 22:21:18 +03:00 committed by Daniel Roe
parent 1730958841
commit da019ba39a
No known key found for this signature in database
GPG Key ID: 3714AB03996F442B

View File

@ -155,7 +155,7 @@ export function useFetch<
let controller: AbortController let controller: AbortController
const asyncData = useAsyncData<_ResT, ErrorT, DataT, PickKeys, DefaultT>(key, () => { const asyncData = useAsyncData<_ResT, ErrorT, DataT, PickKeys, DefaultT>(key, () => {
controller?.abort?.('Request aborted as another request to the same endpoint was initiated.') controller?.abort?.(new DOMException('Request aborted as another request to the same endpoint was initiated.', 'AbortError'))
controller = typeof AbortController !== 'undefined' ? new AbortController() : {} as AbortController controller = typeof AbortController !== 'undefined' ? new AbortController() : {} as AbortController
/** /**
@ -167,7 +167,7 @@ export function useFetch<
const timeoutLength = toValue(opts.timeout) const timeoutLength = toValue(opts.timeout)
let timeoutId: NodeJS.Timeout let timeoutId: NodeJS.Timeout
if (timeoutLength) { if (timeoutLength) {
timeoutId = setTimeout(() => controller.abort('Request aborted due to timeout.'), timeoutLength) timeoutId = setTimeout(() => controller.abort(new DOMException('Request aborted due to timeout.', 'AbortError')), timeoutLength)
controller.signal.onabort = () => clearTimeout(timeoutId) controller.signal.onabort = () => clearTimeout(timeoutId)
} }