@@ -2,6 +2,9 @@ import axios from 'axios'
22
33import Alerts from '../services/alerts.js'
44
5+ import { useAccountAuthStore } from '@/stores/account-auth.js'
6+ import { useUxLoadingStore } from '@/stores/ux-loading.js'
7+
58const client = axios . create ( {
69 headers : {
710 'Content-Type' : 'application/json'
@@ -12,24 +15,18 @@ const client = axios.create({
1215// Common error handler
1316client . interceptors . response . use ( function ( response ) {
1417 return response
15- } , function ( error ) {
18+ } , async function ( error ) {
1619 if ( / ^ h t t p / . test ( error . config . url ) ) {
1720 // This request is to an external URL. Allow this error to pass back to the caller
1821 return Promise . reject ( error )
1922 }
2023
21- // This is an error response from our own API (or failure to reach it)
22- // Lazy require to avoid circular dependency:
23- // api/client.js → stores/account-auth.js → api/user.js → api/client.js
24- const { useAccountAuthStore } = require ( '../stores/account-auth.js' )
25- const { useUxLoadingStore } = require ( '../stores/ux-loading.js' )
26- const store = require ( '../store/index.js' ) . default
2724 if ( error . code === 'ERR_NETWORK' ) {
2825 // Backend failed to respond
2926 useUxLoadingStore ( ) . setOffline ( true )
3027 } else if ( error . response && error . response . status === 401 && ! useUxLoadingStore ( ) . appLoader && ! useAccountAuthStore ( ) . loginInflight ) {
3128 // 401 when !pending && !loginInflight means the session has expired
32- store . dispatch ( 'account/ logout' )
29+ useAccountAuthStore ( ) . logout ( )
3330 } else if ( error . response && error . response . status === 500 ) {
3431 // show toast notification
3532 Alerts . emit ( error . response . data . error + ': ' + error . response . data . message , 'warning' , 7500 )
0 commit comments