@@ -15,10 +15,11 @@ const LS_LANG_KEY = `afLanguage`;
1515const MAX_CONSECUTIVE_EMPTY_RESULTS = 2 ;
1616const ITEMS_PER_PAGE_LIMIT = 100 ;
1717
18- export async function callApi ( { path, method, body, headers} : {
18+ export async function callApi ( { path, method, body, headers, silentError = false } : {
1919 path : string , method : 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
2020 body ?: any
2121 headers ?: Record < string , string >
22+ silentError ?: boolean
2223} ) : Promise < any > {
2324 const t = i18nInstance ?. global . t || ( ( s : string ) => s )
2425 const options = {
@@ -50,18 +51,22 @@ export async function callApi({path, method, body, headers}: {
5051 } else {
5152 await router . push ( { name : 'login' } ) ;
5253 }
53- return null ;
54+ return null ; alert
5455 }
5556 return await r . json ( ) ;
5657 } catch ( e ) {
5758 // if it is internal error, say to user
5859 if ( e instanceof TypeError && e . message === 'Failed to fetch' ) {
5960 // this is a network error
60- adminforth . alert ( { variant :'danger' , message : t ( 'Network error, please check your Internet connection and try again' ) , } )
61+ if ( ! silentError ) {
62+ adminforth . alert ( { variant :'danger' , message : t ( 'Network error, please check your Internet connection and try again' ) , } )
63+ }
6164 return null ;
6265 }
6366
64- adminforth . alert ( { variant :'danger' , message : t ( 'Something went wrong, please try again later' ) , } )
67+ if ( ! silentError ) {
68+ adminforth . alert ( { variant :'danger' , message : t ( 'Something went wrong, please try again later' ) , } )
69+ }
6570 console . error ( `error in callApi ${ path } ` , e ) ;
6671 }
6772}
0 commit comments