Skip to content

Commit 72074a8

Browse files
fix: use NuxtError error type for async data composables
1 parent d6c2fa6 commit 72074a8

File tree

6 files changed

+11
-13
lines changed

6 files changed

+11
-13
lines changed

docs/api/use-kql.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function useKql<
1313
>(
1414
query: MaybeRefOrGetter<ReqT>,
1515
opts?: UseKqlOptions<ResT>
16-
): AsyncData<ResT, FetchError>
16+
): AsyncData<ResT, NuxtError>
1717

1818
type UseKqlOptions<T> = AsyncDataOptions<T> & Pick<
1919
NitroFetchOptions<string>,

playground/nuxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default defineNuxtConfig({
3131
},
3232
},
3333

34-
experimental: {
34+
future: {
3535
typescriptBundlerResolution: true,
3636
},
3737

src/runtime/composables/useKirbyData.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import { computed } from 'vue'
22
import { joinURL } from 'ufo'
33
import { hash } from 'ohash'
4-
import type { FetchError } from 'ofetch'
54
import type { NitroFetchOptions } from 'nitropack'
65
import type { WatchSource } from 'vue'
7-
import type { AsyncData, AsyncDataOptions } from 'nuxt/app'
6+
import type { AsyncData, AsyncDataOptions, NuxtError } from 'nuxt/app'
87
import { toValue } from '@vueuse/core'
98
import type { MaybeRefOrGetter } from '@vueuse/core'
109
import type { ModuleOptions } from '../../module'
@@ -95,7 +94,7 @@ export function useKirbyData<T = any>(
9594

9695
let controller: AbortController | undefined
9796

98-
return useAsyncData<T, FetchError>(
97+
return useAsyncData<T, NuxtError>(
9998
key.value,
10099
async (nuxt) => {
101100
controller?.abort?.()
@@ -153,5 +152,5 @@ export function useKirbyData<T = any>(
153152
}
154153
},
155154
asyncDataOptions,
156-
) as AsyncData<T, FetchError>
155+
) as AsyncData<T, NuxtError>
157156
}

src/runtime/composables/useKql.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { computed } from 'vue'
22
import { hash } from 'ohash'
3-
import type { FetchError } from 'ofetch'
43
import type { NitroFetchOptions } from 'nitropack'
54
import type { WatchSource } from 'vue'
6-
import type { AsyncData, AsyncDataOptions } from 'nuxt/app'
5+
import type { AsyncData, AsyncDataOptions, NuxtError } from 'nuxt/app'
76
import type { KirbyQueryRequest, KirbyQueryResponse } from 'kirby-types'
87
import { toValue } from '@vueuse/core'
98
import type { MaybeRefOrGetter } from '@vueuse/core'
@@ -83,7 +82,7 @@ export function useKql<
8382

8483
let controller: AbortController | undefined
8584

86-
return useAsyncData<ResT, FetchError>(
85+
return useAsyncData<ResT, NuxtError>(
8786
key.value,
8887
async (nuxt) => {
8988
controller?.abort?.()
@@ -141,5 +140,5 @@ export function useKql<
141140
}
142141
},
143142
asyncDataOptions,
144-
) as AsyncData<ResT, FetchError>
143+
) as AsyncData<ResT, NuxtError>
145144
}

src/runtime/server/handler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { createError, defineEventHandler, getRouterParam, readBody } from 'h3'
2-
import type { FetchError } from 'ofetch'
32
import type { ModuleOptions } from '../../module'
43
import { createAuthHeader } from '../utils'
54
import type { ServerFetchOptions } from '../types'
5+
import type { NuxtError } from '#app'
66

77
// @ts-expect-error: Will be resolved by Nitro
88
import { defineCachedFunction } from '#internal/nitro'
@@ -47,7 +47,7 @@ async function fetcher({
4747
statusMessage: isQueryRequest
4848
? 'Failed to execute KQL query'
4949
: `Failed to fetch "${path}"`,
50-
data: (err as FetchError).message,
50+
data: (err as NuxtError).message,
5151
})
5252
}
5353
}

test/fixture/nuxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default defineNuxtConfig({
3535
},
3636
},
3737

38-
experimental: {
38+
future: {
3939
typescriptBundlerResolution: true,
4040
},
4141

0 commit comments

Comments
 (0)