add error handling for on mount useEffect of AuthenticateUserModal

This commit is contained in:
Abhinav 2022-09-06 10:43:41 +05:30
parent f611ff2a6a
commit e0ffb6e9f3

View file

@ -8,6 +8,7 @@ import VerifyMasterPasswordForm, {
VerifyMasterPasswordFormProps, VerifyMasterPasswordFormProps,
} from 'components/VerifyMasterPasswordForm'; } from 'components/VerifyMasterPasswordForm';
import { Dialog, Stack, Typography } from '@mui/material'; import { Dialog, Stack, Typography } from '@mui/material';
import { logError } from 'utils/sentry';
interface Iprops { interface Iprops {
open: boolean; open: boolean;
@ -33,20 +34,28 @@ export default function AuthenticateUserModal({
useEffect(() => { useEffect(() => {
const main = async () => { const main = async () => {
try {
const user = getData(LS_KEYS.USER); const user = getData(LS_KEYS.USER);
if (!user) {
throw Error('User not found');
}
setUser(user); setUser(user);
const keyAttributes = getData(LS_KEYS.KEY_ATTRIBUTES); const keyAttributes = getData(LS_KEYS.KEY_ATTRIBUTES);
if ( if (
(!user?.token && !user?.encryptedToken) || (!user?.token && !user?.encryptedToken) ||
(keyAttributes && !keyAttributes.memLimit) (keyAttributes && !keyAttributes.memLimit)
) { ) {
somethingWentWrong(); throw Error('User not logged in');
} else if (!keyAttributes) { } else if (!keyAttributes) {
somethingWentWrong(); throw Error('Key attributes not found');
} else { } else {
setKeyAttributes(keyAttributes); setKeyAttributes(keyAttributes);
} }
} catch (e) {
logError(e, 'AuthenticateUserModal initialization failed');
onClose();
somethingWentWrong();
}
}; };
main(); main();
}, []); }, []);