Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save randercarlos/6976b6f10fb277ea2ff028636f04b076 to your computer and use it in GitHub Desktop.

Select an option

Save randercarlos/6976b6f10fb277ea2ff028636f04b076 to your computer and use it in GitHub Desktop.
Custom Fetch with Interceptors in Nuxt
export const useCustomFetch = (url: string, options?: FetchOptions) => {
return useFetch(url, {
...options,
async onResponse({ request, response, options }) {
console.log('[fetch response]')
},
async onResponseError({ request, response, options }) {
console.log('[fetch response error]')
},
async onRequest({ request, options }) {
console.log('[fetch request]')
},
async onRequestError({ request, options, error }) {
console.log('[fetch request error]')
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment