diff --git a/docs/2.guide/4.recipes/3.custom-usefetch.md b/docs/2.guide/4.recipes/3.custom-usefetch.md index e8f25f6a2b..1391720db3 100644 --- a/docs/2.guide/4.recipes/3.custom-usefetch.md +++ b/docs/2.guide/4.recipes/3.custom-usefetch.md @@ -96,6 +96,28 @@ const { data: modules } = await useAPI('/modules') ``` +If you want to customize the type of any error returned, you can also do so: + +```ts +import type { FetchError } from 'ofetch' +import type { UseFetchOptions } from 'nuxt/app' + +interface CustomError { + message: string + statusCode: number +} + +export function useAPI( + url: string | (() => string), + options?: UseFetchOptions, +) { + return useFetch>(url, { + ...options, + $fetch: useNuxtApp().$api + }) +} +``` + ::note This example demonstrates how to use a custom `useFetch`, but the same structure is identical for a custom `useAsyncData`. ::