]> Untitled Git - lemmy-ui.git/blob - src/shared/components/common/error-guard.tsx
Handle error when site not returned
[lemmy-ui.git] / src / shared / components / common / error-guard.tsx
1 import { Component } from "inferno";
2 import { ErrorPageData, setIsoData } from "../../utils";
3 import { ErrorPage } from "../app/error-page";
4
5 class ErrorGuard extends Component<any, any> {
6   private isoData = setIsoData(this.context);
7
8   constructor(props: any, context: any) {
9     super(props, context);
10   }
11
12   render() {
13     const errorPageData = this.isoData.routeData[0] as
14       | ErrorPageData
15       | undefined;
16     const siteRes = this.isoData.site_res;
17
18     if (errorPageData?.type === "error" || !siteRes) {
19       return <ErrorPage />;
20     } else {
21       return this.props.children;
22     }
23   }
24 }
25
26 export default ErrorGuard;