11import { onMounted , ref , resolveComponent } from 'vue' ;
22import type { CoreConfig } from './spa_types/core' ;
33import type { ValidationObject } from './types/AdminForthConfig' ;
4-
5-
64import router from "./router" ;
75import { useCoreStore } from './stores/core' ;
86import { useUserStore } from './stores/user' ;
97import { Dropdown } from 'flowbite' ;
108
9+
1110const LS_LANG_KEY = `afLanguage` ;
1211
1312export async function callApi ( { path, method, body= undefined } : {
@@ -23,13 +22,18 @@ export async function callApi({path, method, body=undefined}: {
2322 body : JSON . stringify ( body ) ,
2423 } ;
2524 const fullPath = `${ import . meta. env . VITE_ADMINFORTH_PUBLIC_PATH || '' } ${ path } ` ;
26- const r = await fetch ( fullPath , options ) ;
27- if ( r . status == 401 ) {
28- useUserStore ( ) . unauthorize ( ) ;
29- await router . push ( { name : 'login' } ) ;
30- return null ;
31- }
32- return await r . json ( ) ;
25+ try {
26+ const r = await fetch ( fullPath , options ) ;
27+ if ( r . status == 401 ) {
28+ useUserStore ( ) . unauthorize ( ) ;
29+ await router . push ( { name : 'login' } ) ;
30+ return null ;
31+ }
32+ return await r . json ( ) ;
33+ } catch ( e ) {
34+ window . adminforth . alert ( { variant :'danger' , message :window . i18n ?. global ?. t ( 'Something went wrong, please try again later' ) , } )
35+ console . error ( `error in callApi ${ path } ` , e ) ;
36+ }
3337}
3438
3539export async function callAdminForthApi ( { path, method, body= undefined , headers= undefined } : {
0 commit comments