await and display errors

This commit is contained in:
arc-alex
2024-05-07 14:20:15 +02:00
committed by Carlos Valente
parent 077c67e912
commit e92f59ac55
2 changed files with 12 additions and 10 deletions
@@ -33,6 +33,7 @@ export default function GSheetSetup(props: GSheetSetupProps) {
const patchStepData = useSheetStore((state) => state.patchStepData);
const authenticationStatus = useSheetStore((state) => state.authenticationStatus);
const setAuthenticationStatus = useSheetStore((state) => state.setAuthenticationStatus);
const authenticationError = useSheetStore((state) => state.stepData.authenticate.error);
/** Check if we are authenticated */
const getAuthStatus = async () => {
@@ -44,6 +45,7 @@ export default function GSheetSetup(props: GSheetSetupProps) {
/** check if the current session has been authenticated */
useEffect(() => {
patchStepData({ authenticate: { available: false, error: '' } });
untilAuthenticated();
}, []);
@@ -150,7 +152,7 @@ export default function GSheetSetup(props: GSheetSetupProps) {
</Panel.Title>
<Panel.ListGroup>
<Panel.Description>Upload Client Secret provided by Google</Panel.Description>
<Panel.Error>{undefined}</Panel.Error>
<Panel.Error>{authenticationError}</Panel.Error>
<Input
type='file'
onChange={handleClientSecret}
@@ -25,9 +25,9 @@ export default function useGoogleSheet() {
/** whether the current session has been authenticated */
const verifyAuth = async (): Promise<{ authenticated: AuthenticationStatus; sheetId: string } | void> => {
try {
return verifyAuthenticationStatus();
} catch (_error) {
/** we do not handle errors here */
return await verifyAuthenticationStatus();
} catch (error) {
patchStepData({ authenticate: { available: false, error: maybeAxiosError(error) } });
}
};
@@ -37,18 +37,18 @@ export default function useGoogleSheet() {
sheetId: string,
): Promise<{ verification_url: string; user_code: string } | void> => {
try {
return requestConnection(file, sheetId);
} catch (_error) {
/** we do not handle errors here */
return await requestConnection(file, sheetId);
} catch (error) {
patchStepData({ authenticate: { available: false, error: maybeAxiosError(error) } });
}
};
/** requests the revoking of an existing authenticated session */
const revoke = async (): Promise<{ authenticated: AuthenticationStatus } | void> => {
try {
return revokeAuthentication();
} catch (_error) {
/** we do not handle errors here */
return await revokeAuthentication();
} catch (error) {
patchStepData({ authenticate: { available: false, error: maybeAxiosError(error) } });
}
};