Skip to content

Commit 1e9a263

Browse files
committed
Improve connect errors
1 parent 7c27575 commit 1e9a263

16 files changed

Lines changed: 334 additions & 180 deletions

packages/connect-react/src/components/append/AppendAfterErrorScreen.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { ExcludeCredentialsMatchError, PasskeyChallengeCancelledError } from '@corbado/web-core';
1+
import type { ConnectError } from '@corbado/web-core';
2+
import { ConnectErrorType } from '@corbado/web-core';
23
import log from 'loglevel';
34
import React, { useCallback, useState } from 'react';
45

@@ -25,15 +26,15 @@ const AppendAfterErrorScreen = ({ attestationOptions }: { attestationOptions: st
2526
setErrorMessage(undefined);
2627
const res = await getConnectService().completeAppend(attestationOptions);
2728
if (res.err) {
28-
if (res.val instanceof ExcludeCredentialsMatchError) {
29-
return handleSituation(AppendSituationCode.ClientExcludeCredentialsMatch);
29+
if (res.val.type === ConnectErrorType.ExcludeCredentialsMatch) {
30+
return handleSituation(AppendSituationCode.ClientExcludeCredentialsMatch, res.val);
3031
}
3132

32-
if (res.val instanceof PasskeyChallengeCancelledError) {
33-
return handleSituation(AppendSituationCode.ClientPasskeyOperationCancelled);
33+
if (res.val.type === ConnectErrorType.Cancel) {
34+
return handleSituation(AppendSituationCode.ClientPasskeyOperationCancelled, res.val);
3435
}
3536

36-
return handleSituation(AppendSituationCode.CboApiNotAvailablePostAuthenticator);
37+
return handleSituation(AppendSituationCode.CboApiNotAvailablePostAuthenticator, res.val);
3738
}
3839

3940
setLoading(false);
@@ -43,7 +44,7 @@ const AppendAfterErrorScreen = ({ attestationOptions }: { attestationOptions: st
4344
});
4445
};
4546

46-
const handleSituation = (situationCode: AppendSituationCode) => {
47+
const handleSituation = (situationCode: AppendSituationCode, error?: ConnectError) => {
4748
log.debug(`situation: ${situationCode}`);
4849

4950
const message = getAppendErrorMessage(situationCode);
@@ -55,14 +56,14 @@ const AppendAfterErrorScreen = ({ attestationOptions }: { attestationOptions: st
5556
case AppendSituationCode.CtApiNotAvailablePreAuthenticator:
5657
case AppendSituationCode.CboApiNotAvailablePreAuthenticator:
5758
case AppendSituationCode.CboApiNotAvailablePostAuthenticator:
58-
void handleErrorHard(situationCode, false);
59+
void handleErrorHard(situationCode, false, error);
5960
break;
6061
case AppendSituationCode.ClientPasskeyOperationCancelled:
6162
setLoading(false);
62-
void handleErrorSoft(situationCode, true, true);
63+
void handleErrorSoft(situationCode, true, true, error);
6364
break;
6465
case AppendSituationCode.ClientExcludeCredentialsMatch:
65-
void handleCredentialExistsError();
66+
void handleCredentialExistsError(error);
6667
break;
6768
case AppendSituationCode.ExplicitSkipByUser:
6869
void handleSkip(situationCode, true);

packages/connect-react/src/components/append/AppendInitScreen.tsx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ExcludeCredentialsMatchError, PasskeyChallengeCancelledError } from '@corbado/web-core';
1+
import { ConnectError, ConnectErrorType } from '@corbado/web-core';
22
import log from 'loglevel';
33
import React, { useCallback, useEffect, useRef, useState } from 'react';
44

@@ -80,11 +80,11 @@ const AppendInitScreen = () => {
8080

8181
const res = await getConnectService().appendInit(ac);
8282
if (res.err) {
83-
if (res.val.ignore) {
83+
if (res.val.type === ConnectErrorType.Cancel) {
8484
return;
8585
}
8686

87-
return handleSituation(AppendSituationCode.CboApiNotAvailablePreAuthenticator);
87+
return handleSituation(AppendSituationCode.CboApiNotAvailablePreAuthenticator, res.val);
8888
}
8989

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

108108
const startAppendRes = await getConnectService().startAppend(appendToken, loadedMs, ac);
109109
if (startAppendRes.err) {
110-
if (startAppendRes.val.ignore) {
110+
if (startAppendRes.val.type === ConnectErrorType.Cancel) {
111111
return;
112112
}
113113

114-
return handleSituation(AppendSituationCode.CboApiNotAvailablePostAuthenticator);
114+
return handleSituation(AppendSituationCode.CboApiNotAvailablePostAuthenticator, startAppendRes.val);
115115
}
116116

117117
if (startAppendRes.val.attestationOptions === '') {
@@ -162,19 +162,19 @@ const AppendInitScreen = () => {
162162

163163
const res = await getConnectService().completeAppend(attestationOptions);
164164
if (res.err) {
165-
if (res.val instanceof ExcludeCredentialsMatchError) {
166-
return handleSituation(AppendSituationCode.ClientExcludeCredentialsMatch);
165+
if (res.val.type === ConnectErrorType.ExcludeCredentialsMatch) {
166+
return handleSituation(AppendSituationCode.ClientExcludeCredentialsMatch, res.val);
167167
}
168168

169-
if (res.val instanceof PasskeyChallengeCancelledError) {
169+
if (res.val.type === ConnectErrorType.Cancel) {
170170
if (showErrorIfCancelled) {
171-
return handleSituation(AppendSituationCode.ClientPasskeyOperationCancelled);
171+
return handleSituation(AppendSituationCode.ClientPasskeyOperationCancelled, res.val);
172172
} else {
173-
return handleSituation(AppendSituationCode.ClientPasskeyOperationCancelledSilent);
173+
return handleSituation(AppendSituationCode.ClientPasskeyOperationCancelledSilent, res.val);
174174
}
175175
}
176176

177-
return handleSituation(AppendSituationCode.CboApiNotAvailablePostAuthenticator);
177+
return handleSituation(AppendSituationCode.CboApiNotAvailablePostAuthenticator, res.val);
178178
}
179179

180180
setAppendLoading(false);
@@ -186,7 +186,7 @@ const AppendInitScreen = () => {
186186
[config, getConnectService, appendLoading, skipping],
187187
);
188188

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

192192
const message = getAppendErrorMessage(situationCode);
@@ -198,20 +198,20 @@ const AppendInitScreen = () => {
198198
case AppendSituationCode.CtApiNotAvailablePreAuthenticator:
199199
case AppendSituationCode.CboApiNotAvailablePreAuthenticator:
200200
case AppendSituationCode.CboApiNotAvailablePostAuthenticator:
201-
void handleErrorHard(situationCode, false);
201+
void handleErrorHard(situationCode, false, error);
202202

203203
statefulLoader.current.finishWithError();
204204
break;
205205
case AppendSituationCode.ClientPasskeyOperationCancelled:
206-
void handleErrorSoft(situationCode, true, true);
206+
void handleErrorSoft(situationCode, true, true, error);
207207
setAppendLoading(false);
208208
break;
209209
case AppendSituationCode.ClientPasskeyOperationCancelledSilent:
210-
void handleErrorSoft(situationCode, true, false);
210+
void handleErrorSoft(situationCode, true, false, error);
211211
setAppendLoading(false);
212212
break;
213213
case AppendSituationCode.ClientExcludeCredentialsMatch:
214-
void handleCredentialExistsError();
214+
void handleCredentialExistsError(error);
215215
setAppendLoading(false);
216216
break;
217217
case AppendSituationCode.DeniedByPartialRollout:

packages/connect-react/src/components/login-second-factor/InitScreen.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PasskeyChallengeCancelledError, PasskeyLoginSource } from '@corbado/web-core';
1+
import { ConnectErrorType, PasskeyChallengeCancelledError, PasskeyLoginSource } from '@corbado/web-core';
22
import type { ConnectLoginStartRsp } from '@corbado/web-core/dist/api/v2';
33
import log from 'loglevel';
44
import React, { useEffect, useRef, useState } from 'react';
@@ -41,7 +41,7 @@ const InitScreen = () => {
4141
statefulLoader.current.start();
4242
const res = await getConnectService().loginInit(ac);
4343
if (res.err) {
44-
if (res.val.ignore) {
44+
if (res.val.type === ConnectErrorType.Cancel) {
4545
return;
4646
}
4747

@@ -75,7 +75,7 @@ const InitScreen = () => {
7575
ac,
7676
);
7777
if (resStart.err) {
78-
if (resStart.val.ignore) {
78+
if (resStart.val.type === ConnectErrorType.Cancel) {
7979
return;
8080
}
8181

packages/connect-react/src/components/login/LoginErrorScreenHard.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { PasskeyChallengeCancelledError, PasskeyLoginSource } from '@corbado/web-core';
1+
import type { ConnectError } from '@corbado/web-core';
2+
import { ConnectErrorType, PasskeyLoginSource } from '@corbado/web-core';
23
import log from 'loglevel';
34
import React, { useState } from 'react';
45

@@ -29,7 +30,7 @@ const LoginErrorScreenHard = ({ previousAssertionOptions }: Props) => {
2930
setLoading(true);
3031
const resStart = await getConnectService().loginStart(currentIdentifier, PasskeyLoginSource.ErrorHard, loadedMs);
3132
if (resStart.err) {
32-
return handleSituation(LoginSituationCode.CboApiNotAvailablePreAuthenticator);
33+
return handleSituation(LoginSituationCode.CboApiNotAvailablePreAuthenticator, resStart.val);
3334
}
3435

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

42-
return handleSituation(LoginSituationCode.CboApiFallbackOperationError, data);
43+
return handleSituation(LoginSituationCode.CboApiFallbackOperationError, undefined, data);
4344
}
4445

4546
setAssertionOptions(resStart.val.assertionOptions);
4647

4748
const resFinish = await getConnectService().loginContinue(resStart.val);
4849
if (resFinish.err) {
49-
if (resFinish.val instanceof PasskeyChallengeCancelledError) {
50+
if (resFinish.val.type === ConnectErrorType.Cancel) {
5051
if (hardErrorCount >= 3) {
51-
return handleSituation(LoginSituationCode.ClientPasskeyOperationCancelledTooManyTimes);
52+
return handleSituation(LoginSituationCode.ClientPasskeyOperationCancelledTooManyTimes, resFinish.val);
5253
}
5354

54-
return handleSituation(LoginSituationCode.ClientPasskeyOperationCancelled);
55+
return handleSituation(LoginSituationCode.ClientPasskeyOperationCancelled, resFinish.val);
5556
}
5657

57-
return handleSituation(LoginSituationCode.CboApiNotAvailablePostAuthenticator);
58+
return handleSituation(LoginSituationCode.CboApiNotAvailablePostAuthenticator, resFinish.val);
5859
}
5960

6061
setLoading(false);
@@ -66,8 +67,8 @@ const LoginErrorScreenHard = ({ previousAssertionOptions }: Props) => {
6667
}
6768
};
6869

69-
const handleSituation = (situationCode: LoginSituationCode, data?: unknown) => {
70-
const messageCode = `situation: ${situationCode}`;
70+
const handleSituation = (situationCode: LoginSituationCode, error?: ConnectError, data?: unknown) => {
71+
const messageCode = `situation: ${situationCode} ${error?.track()}`;
7172
log.debug(messageCode);
7273

7374
const identifier = currentIdentifier;

packages/connect-react/src/components/login/LoginErrorScreenSoft.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PasskeyChallengeCancelledError, PasskeyLoginSource } from '@corbado/web-core';
1+
import { ConnectError, ConnectErrorType, PasskeyLoginSource } from '@corbado/web-core';
22
import log from 'loglevel';
33
import React, { useState } from 'react';
44

@@ -28,7 +28,7 @@ const LoginErrorScreenSoft = ({ previousAssertionOptions }: Props) => {
2828
setLoading(true);
2929
const resStart = await getConnectService().loginStart(currentIdentifier, PasskeyLoginSource.ErrorSoft, loadedMs);
3030
if (resStart.err) {
31-
return handleSituation(LoginSituationCode.CboApiNotAvailablePreAuthenticator);
31+
return handleSituation(LoginSituationCode.CboApiNotAvailablePreAuthenticator, resStart.val);
3232
}
3333

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

41-
return handleSituation(LoginSituationCode.CboApiFallbackOperationError, data);
41+
return handleSituation(LoginSituationCode.CboApiFallbackOperationError, undefined, data);
4242
}
4343

4444
const resFinish = await getConnectService().loginContinue(resStart.val);
4545
if (resFinish.err) {
46-
if (resFinish.val instanceof PasskeyChallengeCancelledError) {
47-
return handleSituation(LoginSituationCode.ClientPasskeyOperationCancelled, resStart.val.assertionOptions);
46+
if (resFinish.val.type === ConnectErrorType.Cancel) {
47+
return handleSituation(
48+
LoginSituationCode.ClientPasskeyOperationCancelled,
49+
resFinish.val,
50+
resStart.val.assertionOptions,
51+
);
4852
}
4953

50-
return handleSituation(LoginSituationCode.CboApiNotAvailablePostAuthenticator);
54+
return handleSituation(LoginSituationCode.CboApiNotAvailablePostAuthenticator, resFinish.val);
5155
}
5256

5357
try {
@@ -58,8 +62,8 @@ const LoginErrorScreenSoft = ({ previousAssertionOptions }: Props) => {
5862
}
5963
};
6064

61-
const handleSituation = (situationCode: LoginSituationCode, data?: unknown) => {
62-
const messageCode = `situation: ${situationCode}`;
65+
const handleSituation = (situationCode: LoginSituationCode, error?: ConnectError, data?: unknown) => {
66+
const messageCode = `situation: ${situationCode} ${error?.track()}`;
6367
log.debug(messageCode);
6468

6569
const identifier = currentIdentifier;

packages/connect-react/src/components/login/LoginHybridScreen.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { PasskeyChallengeCancelledError } from '@corbado/web-core';
1+
import type { ConnectError } from '@corbado/web-core';
2+
import { ConnectErrorType } from '@corbado/web-core';
23
import type { ConnectLoginStartRsp } from '@corbado/web-core/dist/api/v2';
34
import log from 'loglevel';
45
import React, { useCallback, useState } from 'react';
@@ -23,11 +24,11 @@ const LoginHybridScreen = (resStart: ConnectLoginStartRsp) => {
2324
setLoading(true);
2425
const res = await getConnectService().loginContinue(resStart);
2526
if (res.err) {
26-
if (res.val instanceof PasskeyChallengeCancelledError) {
27-
return handleSituation(LoginSituationCode.ClientPasskeyOperationCancelled);
27+
if (res.val.type === ConnectErrorType.Cancel) {
28+
return handleSituation(LoginSituationCode.ClientPasskeyOperationCancelled, res.val);
2829
}
2930

30-
return handleSituation(LoginSituationCode.CboApiNotAvailablePostAuthenticator);
31+
return handleSituation(LoginSituationCode.CboApiNotAvailablePostAuthenticator, res.val);
3132
}
3233

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

40-
const handleSituation = (situationCode: LoginSituationCode) => {
41-
const messageCode = `situation: ${situationCode}`;
41+
const handleSituation = (situationCode: LoginSituationCode, error?: ConnectError) => {
42+
const messageCode = `situation: ${situationCode} ${error?.track()}`;
4243
log.debug(messageCode);
4344

4445
const identifier = currentIdentifier;

0 commit comments

Comments
 (0)