Nuxt - Laravel Sanctum
GitHubNuxt Module
0.6
0.6
  • Getting Started
    • Introduction
    • Installation
  • Usage
    • Configuration
    • Cookie Authentication
    • Token Authentication
  • Composables
    • useSanctumAuth
    • useSanctumUser
    • useSanctumClient
    • useSanctumFetch
    • useLazySanctumFetch
    • useSanctumConfig
    • useSanctumAppConfig
  • Middleware
    • sanctum:auth
    • sanctum:guest
    • Global middleware
  • Hooks
    • sanctum:error
    • sanctum:error:request
    • sanctum:redirect
    • sanctum:init
    • sanctum:refresh
    • sanctum:login
    • sanctum:logout
  • Advanced
    • Interceptors
    • Error handling
    • Logging
    • Token storage
    • Plugin dependencies
    • Breeze Nuxt template
    • Troubleshooting
Powered by GitBook
On this page
Edit on GitHub
  1. Hooks

sanctum:error:request

Subscribe to hook and react to any error thrown by ofetch client during the request.

When you send a request to the API, it could raise an exception even before reaching the remote server. For these cases, ofetch uses onRequestError. All these errors are available via sanctum:error:request hook.

plugins/sanctum-listener.ts
export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.hook('sanctum:error:request', (context) => {
    console.log('Sanctum request error hook triggered', context)
  })
})

Here is what the hook looks like

interface RuntimeNuxtHooks {
  /**
   * Triggers when receiving an error on fetch request.
   */
  'sanctum:error:request': (context: FetchContext) => HookResult
}
Previoussanctum:errorNextsanctum:redirect

Last updated 29 days ago