FetchError type

I've seen import type { FetchError } from 'ofetch', what what's the correct module when handling useFetch() errors?
15 Replies
pyplacca
pyplacca9mo ago
Usually “#imports” or “#app” would have what you’d need from your nuxt app
Alejandro Mery
Alejandro MeryOP9mo ago
I just tried both, no luck 😦 and using ofetch feels dirty
pyplacca
pyplacca9mo ago
It seems neither fetch nor ofetch exports it You can still retrieve the type by doing something like:
type FetchError = ReturnType<typeof useFetch<{}>>[‘error’][‘value’]
type FetchError = ReturnType<typeof useFetch<{}>>[‘error’][‘value’]
replace {} with your data’s type
Alejandro Mery
Alejandro MeryOP9mo ago
thank you 🙂 would this qualify as a bug to report?
pyplacca
pyplacca9mo ago
Oh no. An improvement, sure ofetch doesn’t export the FetchError, or does it? Oh it does 😅 @L422Y @Alejandro Mery Just FetchError works fine @L422Y Using typeof doesn’t yield what you’d expect @Alejandro Mery, this should be easier (what @L422Y said) https://discord.com/channels/473401852243869706/1224809697689862156/1224827570285973655
Alejandro Mery
Alejandro MeryOP9mo ago
Thank you @pyplacca @L422Y
Alejandro Mery
Alejandro MeryOP9mo ago
GitHub
FetchError type · Issue #26628 · nuxt/nuxt
Describe the feature import type { FetchError } from 'ofetch' is generally used to type useFetch() errors, but shouldn't that be exported by #imports or #app? https://discord.com/channe...
pyplacca
pyplacca9mo ago
@Alejandro Mery, you needn't create an issue 😅
Alejandro Mery
Alejandro MeryOP9mo ago
feature request 😅 in case someone searches for FetchError there
pyplacca
pyplacca9mo ago
import import type { FetchError } from 'ofetch' won't work because it's a class like @L422Y mentioned
Alejandro Mery
Alejandro MeryOP9mo ago
should I delete it? comment it please 🙂
pyplacca
pyplacca9mo ago
the import statement should've instead been import { FetchError } from 'ofetch'
Alejandro Mery
Alejandro MeryOP9mo ago
I'll edit the issue after you correct me there :p
pyplacca
pyplacca9mo ago
sure
Alejandro Mery
Alejandro MeryOP9mo ago
I'll close this now 🙂 thank you both!
Want results from more Discord servers?
Add your server