From fe954c434cd7f5038b17f3e01b60450e05088725 Mon Sep 17 00:00:00 2001 From: Mike Laumann Bellika <5175031+MikeBellika@users.noreply.github.com> Date: Tue, 13 Aug 2024 14:31:00 +0200 Subject: [PATCH] fix(nuxt): add reason when aborting request in `useFetch` (#28517) --- packages/nuxt/src/app/composables/fetch.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/nuxt/src/app/composables/fetch.ts b/packages/nuxt/src/app/composables/fetch.ts index 16300aed19..362ef12233 100644 --- a/packages/nuxt/src/app/composables/fetch.ts +++ b/packages/nuxt/src/app/composables/fetch.ts @@ -155,7 +155,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 /** @@ -167,7 +167,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) }