11// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22// SPDX-License-Identifier: Apache-2.0
33
4- import 'package:amplify_core/amplify_core .dart' ;
4+ import 'package:amplify_foundation_dart/amplify_foundation_dart .dart' ;
55import 'package:aws_kinesis_datastreams_dart/src/exception/record_cache_exception.dart' ;
66
77/// Default recovery suggestion for errors.
@@ -13,10 +13,10 @@ const String defaultRecoverySuggestion =
1313/// {@endtemplate}
1414sealed class AmplifyKinesisException extends AmplifyException {
1515 /// {@macro aws_kinesis_datastreams.amplify_kinesis_exception}
16- const AmplifyKinesisException (
17- super .message, {
18- super .recoverySuggestion,
19- super .underlyingException ,
16+ AmplifyKinesisException ({
17+ required super .message,
18+ required super .recoverySuggestion,
19+ super .cause ,
2020 });
2121
2222 /// Maps an arbitrary error into the appropriate [AmplifyKinesisException]
@@ -36,47 +36,49 @@ sealed class AmplifyKinesisException extends AmplifyException {
3636 final RecordCacheDatabaseException e => KinesisStorageException (
3737 e.message,
3838 recoverySuggestion: e.recoverySuggestion,
39- underlyingException: e.cause,
40- ),
41- final Exception e => KinesisUnknownException (
42- e.toString (),
43- underlyingException: e,
39+ cause: e.cause,
4440 ),
41+ final Exception e => KinesisUnknownException (e.toString (), cause: e),
4542 _ => KinesisUnknownException (error.toString ()),
4643 };
44+
45+ @override
46+ String toString () {
47+ final buf = StringBuffer ('AmplifyKinesisException: $message ' );
48+ if (recoverySuggestion.isNotEmpty) {
49+ buf.write ('\n Recovery suggestion: $recoverySuggestion ' );
50+ }
51+ if (cause != null ) buf.write ('\n Caused by: $cause ' );
52+ return buf.toString ();
53+ }
4754}
4855
4956/// {@template aws_kinesis_datastreams.kinesis_storage_exception}
5057/// Thrown when a local cache/database error occurs.
5158/// {@endtemplate}
5259final class KinesisStorageException extends AmplifyKinesisException {
5360 /// {@macro aws_kinesis_datastreams.kinesis_storage_exception}
54- const KinesisStorageException (
55- super . message, {
56- super . recoverySuggestion,
57- super .underlyingException ,
58- });
59-
60- @override
61- String get runtimeTypeName => 'KinesisStorageException' ;
61+ KinesisStorageException (
62+ String message, {
63+ String ? recoverySuggestion,
64+ super .cause ,
65+ }) : super (
66+ message : message,
67+ recoverySuggestion : recoverySuggestion ?? defaultRecoverySuggestion,
68+ ) ;
6269}
6370
6471/// {@template aws_kinesis_datastreams.kinesis_limit_exceeded_exception}
6572/// Thrown when the local cache is full.
6673/// {@endtemplate}
6774final class KinesisLimitExceededException extends AmplifyKinesisException {
6875 /// {@macro aws_kinesis_datastreams.kinesis_limit_exceeded_exception}
69- const KinesisLimitExceededException ({
70- String ? message,
71- String ? recoverySuggestion,
72- }) : super (
73- message ?? 'Cache is full' ,
74- recoverySuggestion:
75- recoverySuggestion ?? 'Call flush() or clearCache().' ,
76- );
77-
78- @override
79- String get runtimeTypeName => 'KinesisLimitExceededException' ;
76+ KinesisLimitExceededException ({String ? message, String ? recoverySuggestion})
77+ : super (
78+ message: message ?? 'Cache is full' ,
79+ recoverySuggestion:
80+ recoverySuggestion ?? 'Call flush() or clearCache().' ,
81+ );
8082}
8183
8284/// {@template aws_kinesis_datastreams.kinesis_validation_exception}
@@ -85,34 +87,30 @@ final class KinesisLimitExceededException extends AmplifyKinesisException {
8587/// {@endtemplate}
8688final class KinesisValidationException extends AmplifyKinesisException {
8789 /// {@macro aws_kinesis_datastreams.kinesis_validation_exception}
88- const KinesisValidationException (super .message, {super .recoverySuggestion});
89-
90- @override
91- String get runtimeTypeName => 'KinesisValidationException' ;
90+ KinesisValidationException (String message, {String ? recoverySuggestion})
91+ : super (
92+ message: message,
93+ recoverySuggestion: recoverySuggestion ?? defaultRecoverySuggestion,
94+ );
9295}
9396
9497/// {@template aws_kinesis_datastreams.kinesis_unknown_exception}
9598/// Catch-all for unexpected errors.
9699/// {@endtemplate}
97100final class KinesisUnknownException extends AmplifyKinesisException {
98101 /// {@macro aws_kinesis_datastreams.kinesis_unknown_exception}
99- const KinesisUnknownException (super .message, {super .underlyingException});
100-
101- @override
102- String get runtimeTypeName => 'KinesisUnknownException' ;
102+ KinesisUnknownException (String message, {super .cause})
103+ : super (message: message, recoverySuggestion: defaultRecoverySuggestion);
103104}
104105
105106/// {@template aws_kinesis_datastreams.client_closed_exception}
106107/// Thrown when an operation is attempted on a closed client.
107108/// {@endtemplate}
108109final class ClientClosedException extends AmplifyKinesisException {
109110 /// {@macro aws_kinesis_datastreams.client_closed_exception}
110- const ClientClosedException ()
111+ ClientClosedException ()
111112 : super (
112- 'Client has been closed' ,
113+ message : 'Client has been closed' ,
113114 recoverySuggestion: 'Create a new AmplifyKinesisClient instance.' ,
114115 );
115-
116- @override
117- String get runtimeTypeName => 'ClientClosedException' ;
118116}
0 commit comments