1 import { useEffect, useState } from 'react';
2 import * as React from 'react';
3 import { useLocation } from 'react-router-dom';
12 } from '@proton/components';
13 import { HTTP_STATUS_CODE } from '@proton/shared/lib/constants';
14 import { RESPONSE_CODE } from '@proton/shared/lib/drive/constants';
15 import { ApiError } from '@proton/shared/lib/fetch/ApiError';
16 import generateUID from '@proton/utils/generateUID';
18 import { useActiveShare } from '../hooks/drive/useActiveShare';
21 children: React.ReactNode;
24 const AppErrorBoundary = ({ children }: Props) => {
25 const location = useLocation();
26 const { setDefaultRoot } = useActiveShare();
27 const [state, setState] = useState<{ id: string; error?: Error }>({
28 id: generateUID('error-boundary'),
33 setState({ id: generateUID('error-boundary') });
37 const handleError = (error: Error) => {
38 setState((prev) => ({ ...prev, error }));
42 const renderError = () => {
43 const { error } = state;
48 if (error instanceof ApiError) {
49 if (error.status === HTTP_STATUS_CODE.INTERNAL_SERVER_ERROR) {
50 return <InternalServerError />;
52 if (error.status === HTTP_STATUS_CODE.NOT_FOUND || error.data?.Code === RESPONSE_CODE.INVALID_ID) {
53 return <NotFoundError />;
55 if (error.status === HTTP_STATUS_CODE.FORBIDDEN) {
56 return <AccessDeniedError />;
60 return <GenericError />;
67 component={<PrivateMainArea>{renderError()}</PrivateMainArea>}
74 export default AppErrorBoundary;