Skip to content

Commit 0e83b55

Browse files
committed
fix: add silentError param for the callApi function to avoid spam of errors
1 parent 5826de5 commit 0e83b55

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

adminforth/spa/src/utils.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ const LS_LANG_KEY = `afLanguage`;
1515
const MAX_CONSECUTIVE_EMPTY_RESULTS = 2;
1616
const 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

Comments
 (0)