Skip to content

Improve connect errors #528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ExcludeCredentialsMatchError, PasskeyChallengeCancelledError } from '@corbado/web-core';
import type { ConnectError } from '@corbado/web-core';
import { ConnectErrorType } from '@corbado/web-core';
import log from 'loglevel';
import React, { useCallback, useState } from 'react';

Expand All @@ -25,15 +26,15 @@ const AppendAfterErrorScreen = ({ attestationOptions }: { attestationOptions: st
setErrorMessage(undefined);
const res = await getConnectService().completeAppend(attestationOptions);
if (res.err) {
if (res.val instanceof ExcludeCredentialsMatchError) {
return handleSituation(AppendSituationCode.ClientExcludeCredentialsMatch);
if (res.val.type === ConnectErrorType.ExcludeCredentialsMatch) {
return handleSituation(AppendSituationCode.ClientExcludeCredentialsMatch, res.val);
}

if (res.val instanceof PasskeyChallengeCancelledError) {
return handleSituation(AppendSituationCode.ClientPasskeyOperationCancelled);
if (res.val.type === ConnectErrorType.Cancel) {
return handleSituation(AppendSituationCode.ClientPasskeyOperationCancelled, res.val);
}

return handleSituation(AppendSituationCode.CboApiNotAvailablePostAuthenticator);
return handleSituation(AppendSituationCode.CboApiNotAvailablePostAuthenticator, res.val);
}

setLoading(false);
Expand All @@ -43,7 +44,7 @@ const AppendAfterErrorScreen = ({ attestationOptions }: { attestationOptions: st
});
};

const handleSituation = (situationCode: AppendSituationCode) => {
const handleSituation = (situationCode: AppendSituationCode, error?: ConnectError) => {
log.debug(`situation: ${situationCode}`);

const message = getAppendErrorMessage(situationCode);
Expand All @@ -55,14 +56,14 @@ const AppendAfterErrorScreen = ({ attestationOptions }: { attestationOptions: st
case AppendSituationCode.CtApiNotAvailablePreAuthenticator:
case AppendSituationCode.CboApiNotAvailablePreAuthenticator:
case AppendSituationCode.CboApiNotAvailablePostAuthenticator:
void handleErrorHard(situationCode, false);
void handleErrorHard(situationCode, false, error);
break;
case AppendSituationCode.ClientPasskeyOperationCancelled:
setLoading(false);
void handleErrorSoft(situationCode, true, true);
void handleErrorSoft(situationCode, true, true, error);
break;
case AppendSituationCode.ClientExcludeCredentialsMatch:
void handleCredentialExistsError();
void handleCredentialExistsError(error);
break;
case AppendSituationCode.ExplicitSkipByUser:
void handleSkip(situationCode, true);
Expand Down
33 changes: 17 additions & 16 deletions packages/connect-react/src/components/append/AppendInitScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ExcludeCredentialsMatchError, PasskeyChallengeCancelledError } from '@corbado/web-core';
import type { ConnectError } from '@corbado/web-core';
import { ConnectErrorType } from '@corbado/web-core';
import log from 'loglevel';
import React, { useCallback, useEffect, useRef, useState } from 'react';

Expand Down Expand Up @@ -80,11 +81,11 @@ const AppendInitScreen = () => {

const res = await getConnectService().appendInit(ac);
if (res.err) {
if (res.val.ignore) {
if (res.val.type === ConnectErrorType.Cancel) {
return;
}

return handleSituation(AppendSituationCode.CboApiNotAvailablePreAuthenticator);
return handleSituation(AppendSituationCode.CboApiNotAvailablePreAuthenticator, res.val);
}

// we load flags from backend first, then we override them with the ones that are specified in the component's config
Expand All @@ -107,11 +108,11 @@ const AppendInitScreen = () => {

const startAppendRes = await getConnectService().startAppend(appendToken, loadedMs, ac);
if (startAppendRes.err) {
if (startAppendRes.val.ignore) {
if (startAppendRes.val.type === ConnectErrorType.Cancel) {
return;
}

return handleSituation(AppendSituationCode.CboApiNotAvailablePostAuthenticator);
return handleSituation(AppendSituationCode.CboApiNotAvailablePostAuthenticator, startAppendRes.val);
}

if (startAppendRes.val.attestationOptions === '') {
Expand Down Expand Up @@ -162,19 +163,19 @@ const AppendInitScreen = () => {

const res = await getConnectService().completeAppend(attestationOptions);
if (res.err) {
if (res.val instanceof ExcludeCredentialsMatchError) {
return handleSituation(AppendSituationCode.ClientExcludeCredentialsMatch);
if (res.val.type === ConnectErrorType.ExcludeCredentialsMatch) {
return handleSituation(AppendSituationCode.ClientExcludeCredentialsMatch, res.val);
}

if (res.val instanceof PasskeyChallengeCancelledError) {
if (res.val.type === ConnectErrorType.Cancel) {
if (showErrorIfCancelled) {
return handleSituation(AppendSituationCode.ClientPasskeyOperationCancelled);
return handleSituation(AppendSituationCode.ClientPasskeyOperationCancelled, res.val);
} else {
return handleSituation(AppendSituationCode.ClientPasskeyOperationCancelledSilent);
return handleSituation(AppendSituationCode.ClientPasskeyOperationCancelledSilent, res.val);
}
}

return handleSituation(AppendSituationCode.CboApiNotAvailablePostAuthenticator);
return handleSituation(AppendSituationCode.CboApiNotAvailablePostAuthenticator, res.val);
}

setAppendLoading(false);
Expand All @@ -186,7 +187,7 @@ const AppendInitScreen = () => {
[config, getConnectService, appendLoading, skipping],
);

const handleSituation = async (situationCode: AppendSituationCode) => {
const handleSituation = async (situationCode: AppendSituationCode, error?: ConnectError) => {
log.debug(`situation: ${situationCode}`);

const message = getAppendErrorMessage(situationCode);
Expand All @@ -198,20 +199,20 @@ const AppendInitScreen = () => {
case AppendSituationCode.CtApiNotAvailablePreAuthenticator:
case AppendSituationCode.CboApiNotAvailablePreAuthenticator:
case AppendSituationCode.CboApiNotAvailablePostAuthenticator:
void handleErrorHard(situationCode, false);
void handleErrorHard(situationCode, false, error);

statefulLoader.current.finishWithError();
break;
case AppendSituationCode.ClientPasskeyOperationCancelled:
void handleErrorSoft(situationCode, true, true);
void handleErrorSoft(situationCode, true, true, error);
setAppendLoading(false);
break;
case AppendSituationCode.ClientPasskeyOperationCancelledSilent:
void handleErrorSoft(situationCode, true, false);
void handleErrorSoft(situationCode, true, false, error);
setAppendLoading(false);
break;
case AppendSituationCode.ClientExcludeCredentialsMatch:
void handleCredentialExistsError();
void handleCredentialExistsError(error);
setAppendLoading(false);
break;
case AppendSituationCode.DeniedByPartialRollout:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PasskeyChallengeCancelledError, PasskeyLoginSource } from '@corbado/web-core';
import { ConnectErrorType, PasskeyChallengeCancelledError, PasskeyLoginSource } from '@corbado/web-core';
import type { ConnectLoginStartRsp } from '@corbado/web-core/dist/api/v2';
import log from 'loglevel';
import React, { useEffect, useRef, useState } from 'react';
Expand Down Expand Up @@ -41,7 +41,7 @@ const InitScreen = () => {
statefulLoader.current.start();
const res = await getConnectService().loginInit(ac);
if (res.err) {
if (res.val.ignore) {
if (res.val.type === ConnectErrorType.Cancel) {
return;
}

Expand Down Expand Up @@ -75,7 +75,7 @@ const InitScreen = () => {
ac,
);
if (resStart.err) {
if (resStart.val.ignore) {
if (resStart.val.type === ConnectErrorType.Cancel) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PasskeyChallengeCancelledError, PasskeyLoginSource } from '@corbado/web-core';
import type { ConnectError } from '@corbado/web-core';
import { ConnectErrorType, PasskeyLoginSource } from '@corbado/web-core';
import log from 'loglevel';
import React, { useState } from 'react';

Expand Down Expand Up @@ -29,7 +30,7 @@ const LoginErrorScreenHard = ({ previousAssertionOptions }: Props) => {
setLoading(true);
const resStart = await getConnectService().loginStart(currentIdentifier, PasskeyLoginSource.ErrorHard, loadedMs);
if (resStart.err) {
return handleSituation(LoginSituationCode.CboApiNotAvailablePreAuthenticator);
return handleSituation(LoginSituationCode.CboApiNotAvailablePreAuthenticator, resStart.val);
}

if (resStart.val.assertionOptions.length === 0) {
Expand All @@ -39,22 +40,22 @@ const LoginErrorScreenHard = ({ previousAssertionOptions }: Props) => {
message: resStart.val.fallbackOperationError.error?.message ?? null,
};

return handleSituation(LoginSituationCode.CboApiFallbackOperationError, data);
return handleSituation(LoginSituationCode.CboApiFallbackOperationError, undefined, data);
}

setAssertionOptions(resStart.val.assertionOptions);

const resFinish = await getConnectService().loginContinue(resStart.val);
if (resFinish.err) {
if (resFinish.val instanceof PasskeyChallengeCancelledError) {
if (resFinish.val.type === ConnectErrorType.Cancel) {
if (hardErrorCount >= 3) {
return handleSituation(LoginSituationCode.ClientPasskeyOperationCancelledTooManyTimes);
return handleSituation(LoginSituationCode.ClientPasskeyOperationCancelledTooManyTimes, resFinish.val);
}

return handleSituation(LoginSituationCode.ClientPasskeyOperationCancelled);
return handleSituation(LoginSituationCode.ClientPasskeyOperationCancelled, resFinish.val);
}

return handleSituation(LoginSituationCode.CboApiNotAvailablePostAuthenticator);
return handleSituation(LoginSituationCode.CboApiNotAvailablePostAuthenticator, resFinish.val);
}

setLoading(false);
Expand All @@ -66,8 +67,8 @@ const LoginErrorScreenHard = ({ previousAssertionOptions }: Props) => {
}
};

const handleSituation = (situationCode: LoginSituationCode, data?: unknown) => {
const messageCode = `situation: ${situationCode}`;
const handleSituation = (situationCode: LoginSituationCode, error?: ConnectError, data?: unknown) => {
const messageCode = `situation: ${situationCode} ${error?.track()}`;
log.debug(messageCode);

const identifier = currentIdentifier;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PasskeyChallengeCancelledError, PasskeyLoginSource } from '@corbado/web-core';
import type { ConnectError } from '@corbado/web-core';
import { ConnectErrorType, PasskeyLoginSource } from '@corbado/web-core';
import log from 'loglevel';
import React, { useState } from 'react';

Expand Down Expand Up @@ -28,7 +29,7 @@ const LoginErrorScreenSoft = ({ previousAssertionOptions }: Props) => {
setLoading(true);
const resStart = await getConnectService().loginStart(currentIdentifier, PasskeyLoginSource.ErrorSoft, loadedMs);
if (resStart.err) {
return handleSituation(LoginSituationCode.CboApiNotAvailablePreAuthenticator);
return handleSituation(LoginSituationCode.CboApiNotAvailablePreAuthenticator, resStart.val);
}

if (resStart.val.assertionOptions.length === 0) {
Expand All @@ -38,16 +39,20 @@ const LoginErrorScreenSoft = ({ previousAssertionOptions }: Props) => {
message: resStart.val.fallbackOperationError.error?.message ?? null,
};

return handleSituation(LoginSituationCode.CboApiFallbackOperationError, data);
return handleSituation(LoginSituationCode.CboApiFallbackOperationError, undefined, data);
}

const resFinish = await getConnectService().loginContinue(resStart.val);
if (resFinish.err) {
if (resFinish.val instanceof PasskeyChallengeCancelledError) {
return handleSituation(LoginSituationCode.ClientPasskeyOperationCancelled, resStart.val.assertionOptions);
if (resFinish.val.type === ConnectErrorType.Cancel) {
return handleSituation(
LoginSituationCode.ClientPasskeyOperationCancelled,
resFinish.val,
resStart.val.assertionOptions,
);
}

return handleSituation(LoginSituationCode.CboApiNotAvailablePostAuthenticator);
return handleSituation(LoginSituationCode.CboApiNotAvailablePostAuthenticator, resFinish.val);
}

try {
Expand All @@ -58,8 +63,8 @@ const LoginErrorScreenSoft = ({ previousAssertionOptions }: Props) => {
}
};

const handleSituation = (situationCode: LoginSituationCode, data?: unknown) => {
const messageCode = `situation: ${situationCode}`;
const handleSituation = (situationCode: LoginSituationCode, error?: ConnectError, data?: unknown) => {
const messageCode = `situation: ${situationCode} ${error?.track()}`;
log.debug(messageCode);

const identifier = currentIdentifier;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PasskeyChallengeCancelledError } from '@corbado/web-core';
import type { ConnectError } from '@corbado/web-core';
import { ConnectErrorType } from '@corbado/web-core';
import type { ConnectLoginStartRsp } from '@corbado/web-core/dist/api/v2';
import log from 'loglevel';
import React, { useCallback, useState } from 'react';
Expand All @@ -23,11 +24,11 @@ const LoginHybridScreen = (resStart: ConnectLoginStartRsp) => {
setLoading(true);
const res = await getConnectService().loginContinue(resStart);
if (res.err) {
if (res.val instanceof PasskeyChallengeCancelledError) {
return handleSituation(LoginSituationCode.ClientPasskeyOperationCancelled);
if (res.val.type === ConnectErrorType.Cancel) {
return handleSituation(LoginSituationCode.ClientPasskeyOperationCancelled, res.val);
}

return handleSituation(LoginSituationCode.CboApiNotAvailablePostAuthenticator);
return handleSituation(LoginSituationCode.CboApiNotAvailablePostAuthenticator, res.val);
}

try {
Expand All @@ -37,8 +38,8 @@ const LoginHybridScreen = (resStart: ConnectLoginStartRsp) => {
}
}, [getConnectService, config, navigateToScreen, currentIdentifier, loading]);

const handleSituation = (situationCode: LoginSituationCode) => {
const messageCode = `situation: ${situationCode}`;
const handleSituation = (situationCode: LoginSituationCode, error?: ConnectError) => {
const messageCode = `situation: ${situationCode} ${error?.track()}`;
log.debug(messageCode);

const identifier = currentIdentifier;
Expand Down
Loading
Loading