@@ -27,31 +27,27 @@ sealed class CognitoServiceException extends core.AuthServiceException {
27
27
/// {@endtemplate}
28
28
final class LambdaException extends CognitoServiceException {
29
29
/// {@macro amplify_auth_cognito_dart.sdk.lambda_exception}
30
- factory LambdaException (
31
- String message, {
32
- String ? recoverySuggestion,
33
- Object ? underlyingException,
34
- }) {
35
- final match = _errorRegex.firstMatch (message);
36
- final lambdaName = match? .group (1 );
37
- final parsedMessage = match? .group (2 );
38
- if (parsedMessage != null ) {
39
- message = parsedMessage;
40
- }
41
- return LambdaException ._(
42
- message,
43
- lambdaName: lambdaName,
44
- recoverySuggestion: recoverySuggestion,
45
- underlyingException: underlyingException,
46
- );
47
- }
48
-
49
- const LambdaException ._(
30
+ const LambdaException (
50
31
super .message, {
51
- this .lambdaName,
52
32
super .recoverySuggestion,
53
33
super .underlyingException,
54
- });
34
+ }) : _message = message;
35
+
36
+ final String _message;
37
+
38
+ @override
39
+ String get message {
40
+ final match = _errorRegex.firstMatch (_message);
41
+ final parsedMessage = match? .group (2 );
42
+ return parsedMessage ?? _message;
43
+ }
44
+
45
+ /// The name of the lambda which triggered this exception.
46
+ String ? get lambdaName {
47
+ final match = _errorRegex.firstMatch (_message);
48
+ final lambdaName = match? .group (1 );
49
+ return lambdaName;
50
+ }
55
51
56
52
/// Whether [exception] originated in a user Lambda.
57
53
static bool isLambdaException (String exception) =>
@@ -65,9 +61,6 @@ final class LambdaException extends CognitoServiceException {
65
61
/// errors.
66
62
static final RegExp _errorRegex = RegExp (r'(\w+) failed with error (.*)\.' );
67
63
68
- /// The name of the lambda which triggered this exception.
69
- final String ? lambdaName;
70
-
71
64
@override
72
65
String get runtimeTypeName => 'LambdaException' ;
73
66
}
@@ -227,7 +220,7 @@ final class InvalidEmailRoleAccessPolicyException
227
220
/// {@template amplify_auth_cognito_dart.sdk_exception.invalid_lambda_response_exception}
228
221
/// This exception is thrown when Amazon Cognito encounters an invalid Lambda response.
229
222
/// {@endtemplate}
230
- final class InvalidLambdaResponseException extends CognitoServiceException {
223
+ final class InvalidLambdaResponseException extends LambdaException {
231
224
/// {@macro amplify_auth_cognito_dart.sdk_exception.invalid_lambda_response_exception}
232
225
const InvalidLambdaResponseException (
233
226
super .message, {
@@ -456,7 +449,7 @@ final class UnauthorizedException extends CognitoServiceException {
456
449
/// {@template amplify_auth_cognito_dart.sdk_exception.unexpected_lambda_exception}
457
450
/// This exception is thrown when Amazon Cognito encounters an unexpected exception with Lambda.
458
451
/// {@endtemplate}
459
- final class UnexpectedLambdaException extends CognitoServiceException {
452
+ final class UnexpectedLambdaException extends LambdaException {
460
453
/// {@macro amplify_auth_cognito_dart.sdk_exception.unexpected_lambda_exception}
461
454
const UnexpectedLambdaException (
462
455
super .message, {
@@ -501,7 +494,7 @@ final class UnsupportedTokenTypeException extends CognitoServiceException {
501
494
/// {@template amplify_auth_cognito_dart.sdk_exception.user_lambda_validation_exception}
502
495
/// This exception is thrown when the Amazon Cognito service encounters a user validation exception with the Lambda service.
503
496
/// {@endtemplate}
504
- final class UserLambdaValidationException extends CognitoServiceException {
497
+ final class UserLambdaValidationException extends LambdaException {
505
498
/// {@macro amplify_auth_cognito_dart.sdk_exception.user_lambda_validation_exception}
506
499
const UserLambdaValidationException (
507
500
super .message, {
@@ -615,15 +608,6 @@ Object transformSdkException(Object e) {
615
608
final message = e.message ?? 'An unknown error occurred' ;
616
609
final shapeName = e.shapeId? .shape;
617
610
618
- // Some exceptions are returned as non-Lambda exceptions even though they
619
- // orginated in user-defined lambdas.
620
- if (LambdaException .isLambdaException (message) ||
621
- shapeName == 'InvalidLambdaResponseException' ||
622
- shapeName == 'UnexpectedLambdaException' ||
623
- shapeName == 'UserLambdaValidationException' ) {
624
- return LambdaException (message, underlyingException: e);
625
- }
626
-
627
611
return switch (shapeName) {
628
612
'AliasExistsException' => AliasExistsException (
629
613
message,
@@ -766,6 +750,13 @@ Object transformSdkException(Object e) {
766
750
message,
767
751
underlyingException: e,
768
752
),
769
- _ => UnknownServiceException (message, underlyingException: e),
753
+ _ => (() {
754
+ // Some exceptions are returned as non-Lambda exceptions even though they
755
+ // originated in user-defined lambdas.
756
+ if (LambdaException .isLambdaException (message)) {
757
+ return LambdaException (message, underlyingException: e);
758
+ }
759
+ return UnknownServiceException (message, underlyingException: e);
760
+ })(),
770
761
};
771
762
}
0 commit comments