improve error handling for getAuthCodes flow
This commit is contained in:
parent
863752eb56
commit
fafaf90a19
|
@ -22,8 +22,6 @@ const AuthenticatorCodesPage = () => {
|
|||
if (err.message === CustomError.KEY_MISSING) {
|
||||
appContext.setRedirectURL(PAGES.AUTH);
|
||||
router.push(PAGES.ROOT);
|
||||
} else {
|
||||
// do not log errors
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -4,6 +4,7 @@ import { Code } from 'types/authenticator/code';
|
|||
import ComlinkCryptoWorker from 'utils/comlink/ComlinkCryptoWorker';
|
||||
import { getEndpoint } from 'utils/common/apiUtil';
|
||||
import { getActualKey, getToken } from 'utils/common/key';
|
||||
import { CustomError } from 'utils/error';
|
||||
import { logError } from 'utils/sentry';
|
||||
|
||||
const ENDPOINT = getEndpoint();
|
||||
|
@ -12,11 +13,16 @@ export const getAuthCodes = async (): Promise<Code[]> => {
|
|||
try {
|
||||
const authKeyData = await getAuthKey();
|
||||
const cryptoWorker = await ComlinkCryptoWorker.getInstance();
|
||||
const authenticatorKey = await cryptoWorker.decryptB64(
|
||||
let authenticatorKey: string;
|
||||
try {
|
||||
authenticatorKey = await cryptoWorker.decryptB64(
|
||||
authKeyData.encryptedKey,
|
||||
authKeyData.header,
|
||||
masterKey
|
||||
);
|
||||
} catch (e) {
|
||||
throw Error(CustomError.DECRYPTION_FAILED);
|
||||
}
|
||||
// always fetch all data from server for now
|
||||
const authEntity: AuthEntity[] = await getDiff(0);
|
||||
const authCodes = await Promise.all(
|
||||
|
@ -56,7 +62,9 @@ export const getAuthCodes = async (): Promise<Code[]> => {
|
|||
});
|
||||
return authCodes;
|
||||
} catch (e) {
|
||||
if (e.message !== CustomError.AUTH_KEY_NOT_FOUND) {
|
||||
logError(e, 'get authenticator entities failed');
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
@ -72,9 +80,13 @@ export const getAuthKey = async (): Promise<AuthKey> => {
|
|||
);
|
||||
return resp.data;
|
||||
} catch (e) {
|
||||
if (e.status === 404) {
|
||||
throw Error(CustomError.AUTH_KEY_NOT_FOUND);
|
||||
} else {
|
||||
logError(e, 'Get key failed');
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// return a promise which resolves to list of AuthEnitity
|
||||
|
|
|
@ -58,6 +58,8 @@ export const CustomError = {
|
|||
NO_EXPORT_FOLDER_SELECTED: 'no export folder selected',
|
||||
EXPORT_FOLDER_DOES_NOT_EXIST: 'export folder does not exist',
|
||||
NO_INTERNET_CONNECTION: 'no internet connection',
|
||||
AUTH_KEY_NOT_FOUND: 'auth key not found',
|
||||
DECRYPTION_FAILED: 'decryption failed',
|
||||
};
|
||||
|
||||
export function parseUploadErrorCodes(error) {
|
||||
|
|
Loading…
Reference in a new issue