Skip to content

Commit 38404e0

Browse files
feat: modified notify utility
1 parent 5c11ef7 commit 38404e0

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

messages/index.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,20 @@ class Notify {
88
}
99

1010
// if someone call notify.error(), make an error toast
11-
error(error: any) {
11+
error(error: any, fallback: string = "An error occurred") {
1212
if (typeof error === "string") {
1313
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);
1421
} else if (error.message && typeof error.message === "string") {
1522
toast.error(error.message);
1623
} else {
17-
toast.error("An error occurred");
24+
toast.error(fallback);
1825
}
1926
}
2027

@@ -29,6 +36,9 @@ class Notify {
2936
icon: "⚠️",
3037
});
3138
}
39+
40+
// promise
41+
promise = toast.promise;
3242
}
3343

3444
const notify = new Notify();

0 commit comments

Comments
 (0)