Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/resources/scripts/components/elements/ErrorBoundary.tsx
7461 views
1
import React from 'react';
2
import tw from 'twin.macro';
3
import Icon from '@/components/elements/Icon';
4
import { faExclamationTriangle } from '@fortawesome/free-solid-svg-icons';
5
6
interface State {
7
hasError: boolean;
8
}
9
10
// eslint-disable-next-line @typescript-eslint/ban-types
11
class ErrorBoundary extends React.Component<{}, State> {
12
state: State = {
13
hasError: false,
14
};
15
16
static getDerivedStateFromError() {
17
return { hasError: true };
18
}
19
20
componentDidCatch(error: Error) {
21
console.error(error);
22
}
23
24
render() {
25
return this.state.hasError ? (
26
<div css={tw`flex items-center justify-center w-full my-4`}>
27
<div css={tw`flex items-center bg-neutral-900 rounded p-3 text-red-500`}>
28
<Icon icon={faExclamationTriangle} css={tw`h-4 w-auto mr-2`} />
29
<p css={tw`text-sm text-neutral-100`}>
30
An error was encountered by the application while rendering this view. Try refreshing the page.
31
</p>
32
</div>
33
</div>
34
) : (
35
this.props.children
36
);
37
}
38
}
39
40
export default ErrorBoundary;
41
42