Hey is a decentralized and permissionless social media app built with Lens Protocol 馃尶
1import { ERRORS } from "@hey/data/errors";
2import { toast } from "sonner";
3
4const FORBIDDEN_ERROR_PREFIX =
5 "Forbidden - Failed to generate source stamp: App rejected verification request:";
6const CONNECTOR_ERROR = "Connector not connected";
7
8interface ErrorPayload {
9 message?: string;
10 data?: {
11 message?: string;
12 };
13}
14
15const getMessage = (err?: unknown): string | undefined => {
16 if (!err) return undefined;
17 if (typeof err === "string") return err;
18 if (err instanceof Error) return err.message;
19
20 const error = err as ErrorPayload;
21 return error.data?.message ?? error.message;
22};
23
24const errorToast = (error?: unknown): void => {
25 const message = getMessage(error);
26
27 if (!message || message.includes("viem")) return;
28
29 if (message.includes(FORBIDDEN_ERROR_PREFIX)) {
30 toast.error(message.replace(FORBIDDEN_ERROR_PREFIX, ""), { id: "error" });
31 return;
32 }
33
34 if (message.includes(CONNECTOR_ERROR)) {
35 toast.error("Connect or switch to the correct wallet!", {
36 id: "connector-error"
37 });
38 return;
39 }
40
41 toast.error(message || ERRORS.SomethingWentWrong, { id: "error" });
42};
43
44export default errorToast;