Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/runtime/composables/useStrapiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ const defaultErrors = (err: FetchError) => ({
}
})

const fallbackError = (err: FetchError) => ({
error: {
status: err.statusCode || 500,
name: err.name || 'UnknownError',
message: err.message || 'UnknownError',
details: err
}
})

export const useStrapiClient = () => {
const nuxt = useNuxtApp()
const baseURL = useStrapiUrl()
Expand Down Expand Up @@ -57,7 +66,10 @@ export const useStrapiClient = () => {
}
})
} catch (err) {
const e: Strapi4Error | Strapi3Error = err.data || defaultErrors(err)[version]
const e: Strapi4Error | Strapi3Error
= err.data
|| defaultErrors(err)[version]
|| fallbackError(err)

nuxt.hooks.callHook('strapi:error', e)
throw e
Expand Down
Loading