Import FetchError type
Hi! What is the current method of importing
FetchError
type?
Ref: https://discord.com/channels/473401852243869706/1224809697689862156
Ref: https://github.com/nuxt/nuxt/issues/26628
I do not think FetchError
should be imported from ofetch
. Using error type from package may fail instanceof
. It is also explicitly recommended to use $fetch
instead of importing from ofetch
.
3 Replies
Hi @Mole. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
I'm sorry, but the knowledge sources provided do not explicitly document the recommended way to import the FetchError type in Nuxt 3, nor do they clarify whether you should import it from ofetch or another source. The available documentation and examples show usage of FetchError from ofetch in custom composables, such as:
This is demonstrated in the official Nuxt recipe for creating a custom useFetch composable, where FetchError is imported from ofetch and used as the error type parameter for useFetch:
Custom useFetch in Nuxt
However, the sources do not address the concern about instanceof checks or provide an alternative to importing FetchError from ofetch. If you need strict instanceof compatibility with errors thrown by $fetch in Nuxt, the documentation does not clarify whether importing FetchError from ofetch is sufficient or if there is a Nuxt-specific type you should use.
If you require further clarification, you may need to consult the Nuxt core team or check for updates in the official documentation or GitHub issues, as the current knowledge sources do not provide a definitive answer.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@522852263979384852> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
Surprisingly good response for AI. Does not answer the question tho :)