-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathErrorModal.tsx
58 lines (55 loc) · 1.61 KB
/
ErrorModal.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { Button, Group, Modal, ScrollArea, Stack, Title } from "@mantine/core";
import { useEffect, useState } from "react";
import { CodeWithCopy } from "@/components/CodeWithCopy";
export const ErrorModal: React.FC = () => {
const [unhandledRejectionError, setUnhandledRejectionError] = useState<
string | null
>(null);
useEffect(() => {
const handleUnhandledRejection = (event: PromiseRejectionEvent) => {
setUnhandledRejectionError(
(event.reason as Error).message || "Unknown error",
);
};
window.addEventListener("unhandledrejection", handleUnhandledRejection);
return () => {
window.removeEventListener(
"unhandledrejection",
handleUnhandledRejection,
);
};
}, []);
return unhandledRejectionError ? (
<Modal
opened={!!unhandledRejectionError}
onClose={() => {
setUnhandledRejectionError(null);
}}
withCloseButton={false}
centered>
<Stack gap="md">
<Title order={4}>Application error</Title>
<ScrollArea>
<CodeWithCopy
code={JSON.stringify(unhandledRejectionError, null, 2)}
/>
</ScrollArea>
<Group justify="space-between">
<Button
variant="default"
component="a"
href="https://github.com/xmtp/xmtp-js/issues/new/choose"
target="_blank">
Report issue
</Button>
<Button
onClick={() => {
setUnhandledRejectionError(null);
}}>
OK
</Button>
</Group>
</Stack>
</Modal>
) : null;
};