fix(nuxt): add reason when aborting request in `useFetch` (#28517)

This commit is contained in:
Mike Laumann Bellika 2024-08-13 14:31:00 +02:00 committed by GitHub
parent c92b2df903
commit 8c4a62b950
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 2 deletions

View File

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