11// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22// SPDX-License-Identifier: Apache-2.0
33
4- import 'package:amplify_foundation_dart/amplify_foundation_dart .dart' ;
4+ import 'package:amplify_core/amplify_core .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- AmplifyKinesisException ({
17- required super .message,
18- required super .recoverySuggestion,
19- super .cause ,
16+ const AmplifyKinesisException (
17+ super .message, {
18+ super .recoverySuggestion,
19+ super .underlyingException ,
2020 });
2121
2222 /// Maps an arbitrary error into the appropriate [AmplifyKinesisException]
@@ -36,49 +36,47 @@ sealed class AmplifyKinesisException extends AmplifyException {
3636 final RecordCacheDatabaseException e => KinesisStorageException (
3737 e.message,
3838 recoverySuggestion: e.recoverySuggestion,
39- cause: e.cause,
39+ underlyingException: e.cause,
40+ ),
41+ final Exception e => KinesisUnknownException (
42+ e.toString (),
43+ underlyingException: e,
4044 ),
41- final Exception e => KinesisUnknownException (e.toString (), cause: e),
4245 _ => KinesisUnknownException (error.toString ()),
4346 };
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- }
5447}
5548
5649/// {@template aws_kinesis_datastreams.kinesis_storage_exception}
5750/// Thrown when a local cache/database error occurs.
5851/// {@endtemplate}
5952final class KinesisStorageException extends AmplifyKinesisException {
6053 /// {@macro aws_kinesis_datastreams.kinesis_storage_exception}
61- KinesisStorageException (
62- String message, {
63- String ? recoverySuggestion,
64- super .cause ,
65- }) : super (
66- message : message,
67- recoverySuggestion : recoverySuggestion ?? defaultRecoverySuggestion,
68- ) ;
54+ const KinesisStorageException (
55+ super . message, {
56+ super . recoverySuggestion,
57+ super .underlyingException ,
58+ });
59+
60+ @override
61+ String get runtimeTypeName => 'KinesisStorageException' ;
6962}
7063
7164/// {@template aws_kinesis_datastreams.kinesis_limit_exceeded_exception}
7265/// Thrown when the local cache is full.
7366/// {@endtemplate}
7467final class KinesisLimitExceededException extends AmplifyKinesisException {
7568 /// {@macro aws_kinesis_datastreams.kinesis_limit_exceeded_exception}
76- KinesisLimitExceededException ({String ? message, String ? recoverySuggestion})
77- : super (
78- message: message ?? 'Cache is full' ,
79- recoverySuggestion:
80- recoverySuggestion ?? 'Call flush() or clearCache().' ,
81- );
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' ;
8280}
8381
8482/// {@template aws_kinesis_datastreams.kinesis_validation_exception}
@@ -87,30 +85,34 @@ final class KinesisLimitExceededException extends AmplifyKinesisException {
8785/// {@endtemplate}
8886final class KinesisValidationException extends AmplifyKinesisException {
8987 /// {@macro aws_kinesis_datastreams.kinesis_validation_exception}
90- KinesisValidationException (String message, {String ? recoverySuggestion})
91- : super (
92- message: message,
93- recoverySuggestion: recoverySuggestion ?? defaultRecoverySuggestion,
94- );
88+ const KinesisValidationException (super .message, {super .recoverySuggestion});
89+
90+ @override
91+ String get runtimeTypeName => 'KinesisValidationException' ;
9592}
9693
9794/// {@template aws_kinesis_datastreams.kinesis_unknown_exception}
9895/// Catch-all for unexpected errors.
9996/// {@endtemplate}
10097final class KinesisUnknownException extends AmplifyKinesisException {
10198 /// {@macro aws_kinesis_datastreams.kinesis_unknown_exception}
102- KinesisUnknownException (String message, {super .cause})
103- : super (message: message, recoverySuggestion: defaultRecoverySuggestion);
99+ const KinesisUnknownException (super .message, {super .underlyingException});
100+
101+ @override
102+ String get runtimeTypeName => 'KinesisUnknownException' ;
104103}
105104
106105/// {@template aws_kinesis_datastreams.client_closed_exception}
107106/// Thrown when an operation is attempted on a closed client.
108107/// {@endtemplate}
109108final class ClientClosedException extends AmplifyKinesisException {
110109 /// {@macro aws_kinesis_datastreams.client_closed_exception}
111- ClientClosedException ()
110+ const ClientClosedException ()
112111 : super (
113- message : 'Client has been closed' ,
112+ 'Client has been closed' ,
114113 recoverySuggestion: 'Create a new AmplifyKinesisClient instance.' ,
115114 );
115+
116+ @override
117+ String get runtimeTypeName => 'ClientClosedException' ;
116118}
0 commit comments