sanctum:error:response

Subscribe to hook and react to any error received from your Laravel API.

When you send a request to Laravel API using any available module's composable, it may return an error, such as 401, 419, 403, 404, etc.

However, if you need more granular control over API errors, you can subscribe to the sanctum:error hook and process the HTTP response according to your requirements.

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

Here is what the hook looks like

interface RuntimeNuxtHooks {
  /**
   * Triggers when receiving an error response.
   */
  'sanctum:error:response': (response: FetchResponse<any>) => HookResult
}

Last updated