adminforth 2.13.0-next.59 → 2.13.0-next.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/spa/src/utils.ts +9 -4
- package/package.json +1 -1
package/dist/spa/src/utils.ts
CHANGED
|
@@ -15,10 +15,11 @@ const LS_LANG_KEY = `afLanguage`;
|
|
|
15
15
|
const MAX_CONSECUTIVE_EMPTY_RESULTS = 2;
|
|
16
16
|
const ITEMS_PER_PAGE_LIMIT = 100;
|
|
17
17
|
|
|
18
|
-
export async function callApi({path, method, body, headers}: {
|
|
18
|
+
export async function callApi({path, method, body, headers, silentError = false}: {
|
|
19
19
|
path: string, method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
|
|
20
20
|
body?: any
|
|
21
21
|
headers?: Record<string, string>
|
|
22
|
+
silentError?: boolean
|
|
22
23
|
}): Promise<any> {
|
|
23
24
|
const t = i18nInstance?.global.t || ((s: string) => s)
|
|
24
25
|
const options = {
|
|
@@ -50,18 +51,22 @@ export async function callApi({path, method, body, headers}: {
|
|
|
50
51
|
} else {
|
|
51
52
|
await router.push({ name: 'login' });
|
|
52
53
|
}
|
|
53
|
-
return null;
|
|
54
|
+
return null;alert
|
|
54
55
|
}
|
|
55
56
|
return await r.json();
|
|
56
57
|
} catch(e) {
|
|
57
58
|
// if it is internal error, say to user
|
|
58
59
|
if (e instanceof TypeError && e.message === 'Failed to fetch') {
|
|
59
60
|
// this is a network error
|
|
60
|
-
|
|
61
|
+
if (!silentError) {
|
|
62
|
+
adminforth.alert({variant:'danger', message: t('Network error, please check your Internet connection and try again'),})
|
|
63
|
+
}
|
|
61
64
|
return null;
|
|
62
65
|
}
|
|
63
66
|
|
|
64
|
-
|
|
67
|
+
if (!silentError) {
|
|
68
|
+
adminforth.alert({variant:'danger', message: t('Something went wrong, please try again later'),})
|
|
69
|
+
}
|
|
65
70
|
console.error(`error in callApi ${path}`, e);
|
|
66
71
|
}
|
|
67
72
|
}
|