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,19 +34,27 @@ export default function AuthenticateUserModal({
useEffect(() => { useEffect(() => {
const main = async () => { const main = async () => {
const user = getData(LS_KEYS.USER); try {
setUser(user); const user = getData(LS_KEYS.USER);
const keyAttributes = getData(LS_KEYS.KEY_ATTRIBUTES); if (!user) {
throw Error('User not found');
if ( }
(!user?.token && !user?.encryptedToken) || setUser(user);
(keyAttributes && !keyAttributes.memLimit) const keyAttributes = getData(LS_KEYS.KEY_ATTRIBUTES);
) { if (
(!user?.token && !user?.encryptedToken) ||
(keyAttributes && !keyAttributes.memLimit)
) {
throw Error('User not logged in');
} else if (!keyAttributes) {
throw Error('Key attributes not found');
} else {
setKeyAttributes(keyAttributes);
}
} catch (e) {
logError(e, 'AuthenticateUserModal initialization failed');
onClose();
somethingWentWrong(); somethingWentWrong();
} else if (!keyAttributes) {
somethingWentWrong();
} else {
setKeyAttributes(keyAttributes);
} }
}; };
main(); main();