@data-fair/lib-vue 1.13.1 → 1.13.3
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/async-action.d.ts +2 -2
- package/async-action.js +4 -4
- package/package.json +1 -1
- package/ui-notif.d.ts +4 -0
- package/ui-notif.js +11 -1
package/async-action.d.ts
CHANGED
|
@@ -7,8 +7,8 @@ type AsyncActionOptions = {
|
|
|
7
7
|
};
|
|
8
8
|
export declare function asyncAction<F extends (...args: any[]) => Promise<any>>(fn: F, options?: AsyncActionOptions): {
|
|
9
9
|
execute: F;
|
|
10
|
-
notif: Ref<UiNotif |
|
|
10
|
+
notif: Ref<UiNotif | undefined>;
|
|
11
11
|
loading: Ref<boolean>;
|
|
12
|
-
error: Ref<string |
|
|
12
|
+
error: Ref<string | undefined>;
|
|
13
13
|
};
|
|
14
14
|
export {};
|
package/async-action.js
CHANGED
|
@@ -3,13 +3,13 @@ import { ref } from 'vue'
|
|
|
3
3
|
import { useUiNotif, getFullNotif, getErrorMsg } from './ui-notif.js'
|
|
4
4
|
export function asyncAction (fn, options) {
|
|
5
5
|
const { sendUiNotif } = useUiNotif()
|
|
6
|
-
const notif = ref(
|
|
6
|
+
const notif = ref()
|
|
7
7
|
const loading = ref(false)
|
|
8
|
-
const error = ref(
|
|
8
|
+
const error = ref()
|
|
9
9
|
const execute = async function (...args) {
|
|
10
10
|
loading.value = true
|
|
11
|
-
notif.value =
|
|
12
|
-
error.value =
|
|
11
|
+
notif.value = undefined
|
|
12
|
+
error.value = undefined
|
|
13
13
|
try {
|
|
14
14
|
const result = await fn(...args)
|
|
15
15
|
if (options?.success) {
|
package/package.json
CHANGED
package/ui-notif.d.ts
CHANGED
|
@@ -16,7 +16,9 @@ interface UiNotifError {
|
|
|
16
16
|
msg: string;
|
|
17
17
|
error: any;
|
|
18
18
|
errorMsg: string;
|
|
19
|
+
clientError?: boolean;
|
|
19
20
|
}
|
|
21
|
+
export declare function getErrorCode(error: any): number;
|
|
20
22
|
export declare function getErrorMsg(error: any): string;
|
|
21
23
|
export declare function getFullNotif(notif: PartialUiNotif, defaultType?: UiNotifBase['type']): UiNotif;
|
|
22
24
|
export declare const getUiNotif: () => {
|
|
@@ -28,6 +30,7 @@ export declare const getUiNotif: () => {
|
|
|
28
30
|
msg: string;
|
|
29
31
|
error: any;
|
|
30
32
|
errorMsg: string;
|
|
33
|
+
clientError?: boolean | undefined;
|
|
31
34
|
} | null, UiNotif | {
|
|
32
35
|
type?: ("default" | "info" | "success" | "warning") | undefined;
|
|
33
36
|
msg: string;
|
|
@@ -36,6 +39,7 @@ export declare const getUiNotif: () => {
|
|
|
36
39
|
msg: string;
|
|
37
40
|
error: any;
|
|
38
41
|
errorMsg: string;
|
|
42
|
+
clientError?: boolean | undefined;
|
|
39
43
|
} | null>;
|
|
40
44
|
sendUiNotif: (partialNotif: PartialUiNotif) => void;
|
|
41
45
|
};
|
package/ui-notif.js
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
// or can be displayed locally by @data-fair/lib-vuetify/ui-notif.vue
|
|
4
4
|
import { ref, inject } from 'vue'
|
|
5
5
|
import inIframe from '@data-fair/lib-utils/in-iframe.js'
|
|
6
|
+
export function getErrorCode (error) {
|
|
7
|
+
if (typeof error === 'string') { return 500 }
|
|
8
|
+
if (typeof error.statusCode === 'number') { return error.statusCode }
|
|
9
|
+
if (typeof error.response?.statusCode === 'number') { return error.response?.statusCode }
|
|
10
|
+
if (typeof error.code === 'number') { return error.code }
|
|
11
|
+
if (typeof error.response?.code === 'number') { return error.response?.code }
|
|
12
|
+
return 500
|
|
13
|
+
}
|
|
6
14
|
export function getErrorMsg (error) {
|
|
7
15
|
if (typeof error === 'string') { return error }
|
|
8
16
|
if (error.data && typeof error.data === 'string') { return error.data }
|
|
@@ -15,10 +23,12 @@ export function getErrorMsg (error) {
|
|
|
15
23
|
export function getFullNotif (notif, defaultType = 'default') {
|
|
16
24
|
if (typeof notif === 'string') { return { msg: notif, type: defaultType } }
|
|
17
25
|
if (notif.error) {
|
|
26
|
+
const code = getErrorCode(notif.error)
|
|
18
27
|
return {
|
|
19
28
|
...notif,
|
|
20
29
|
type: 'error',
|
|
21
|
-
errorMsg: getErrorMsg(notif.error)
|
|
30
|
+
errorMsg: getErrorMsg(notif.error),
|
|
31
|
+
clientError: code < 500
|
|
22
32
|
}
|
|
23
33
|
}
|
|
24
34
|
return {
|