File tree 1 file changed +12
-2
lines changed
1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -8,13 +8,20 @@ class Notify {
8
8
}
9
9
10
10
// if someone call notify.error(), make an error toast
11
- error ( error : any ) {
11
+ error ( error : any , fallback : string = "An error occurred" ) {
12
12
if ( typeof error === "string" ) {
13
13
toast . error ( error ) ;
14
+ } else if (
15
+ error . response &&
16
+ error . response . data &&
17
+ error . response . data . message &&
18
+ typeof error . response . data . message === "string"
19
+ ) {
20
+ toast . error ( error . response . data . message ) ;
14
21
} else if ( error . message && typeof error . message === "string" ) {
15
22
toast . error ( error . message ) ;
16
23
} else {
17
- toast . error ( "An error occurred" ) ;
24
+ toast . error ( fallback ) ;
18
25
}
19
26
}
20
27
@@ -29,6 +36,9 @@ class Notify {
29
36
icon : "⚠️" ,
30
37
} ) ;
31
38
}
39
+
40
+ // promise
41
+ promise = toast . promise ;
32
42
}
33
43
34
44
const notify = new Notify ( ) ;
You can’t perform that action at this time.
0 commit comments