Skip to content

Commit aafc570

Browse files
fjnoypkyle
andauthored
fix(datastore): hot restart (#3497)
Ignore platform exceptions so that authenticator no longer freezes app with datastore on hot restart. Co-authored-by: kyle <[email protected]>
1 parent 0988a0e commit aafc570

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

packages/amplify_datastore/lib/amplify_datastore.dart

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import 'package:meta/meta.dart';
1515
export 'package:amplify_core/src/types/datastore/datastore_types.dart'
1616
hide DateTimeParse;
1717

18-
class AmplifyDataStore extends DataStorePluginInterface {
18+
class AmplifyDataStore extends DataStorePluginInterface
19+
with AWSDebuggable, AmplifyLoggerMixin {
1920
/// Constructs an AmplifyDataStore plugin with mandatory [modelProvider]
2021
/// and optional datastore configuration properties including
2122
///
@@ -77,16 +78,13 @@ class AmplifyDataStore extends DataStorePluginInterface {
7778
} on PlatformException catch (e) {
7879
if (e.code.contains('AmplifyAlreadyConfiguredException') ||
7980
e.code.contains('AlreadyConfiguredException')) {
80-
throw const AmplifyAlreadyConfiguredException(
81-
AmplifyExceptionMessages.alreadyConfiguredDefaultMessage,
82-
recoverySuggestion:
83-
AmplifyExceptionMessages.alreadyConfiguredDefaultSuggestion,
81+
logger.debug('Ignoring Amplify Native already configured exception');
82+
} else {
83+
throw ConfigurationError(
84+
e.message ?? 'An unknown error occurred',
85+
underlyingException: e,
8486
);
8587
}
86-
throw ConfigurationError(
87-
e.message ?? 'An unknown error occurred',
88-
underlyingException: e,
89-
);
9088
}
9189
// Update the native cache for the current user on hub events.
9290
Future<void> updateCurrentUser(AuthUser? currentUser) async {
@@ -129,16 +127,13 @@ class AmplifyDataStore extends DataStorePluginInterface {
129127
} on PlatformException catch (e) {
130128
if (e.code.contains('AmplifyAlreadyConfiguredException') ||
131129
e.code.contains('AlreadyConfiguredException')) {
132-
throw const AmplifyAlreadyConfiguredException(
133-
AmplifyExceptionMessages.alreadyConfiguredDefaultMessage,
134-
recoverySuggestion:
135-
AmplifyExceptionMessages.alreadyConfiguredDefaultSuggestion,
130+
logger.debug('Ignoring Amplify Native already configured exception');
131+
} else {
132+
throw ConfigurationError(
133+
e.message ?? 'An unknown error occurred',
134+
underlyingException: e,
136135
);
137136
}
138-
throw ConfigurationError(
139-
e.message ?? 'An unknown error occurred',
140-
underlyingException: e,
141-
);
142137
}
143138
}
144139

@@ -154,6 +149,7 @@ class AmplifyDataStore extends DataStorePluginInterface {
154149
Map<String, String>.from(e.details as Map),
155150
);
156151
} else if (e.code == 'AmplifyAlreadyConfiguredException') {
152+
logger.debug('Ignoring Amplify Native already configured exception');
157153
return;
158154
} else {
159155
// This shouldn't happen. All exceptions coming from platform for
@@ -253,6 +249,9 @@ class AmplifyDataStore extends DataStorePluginInterface {
253249
throttleOptions: throttleOptions,
254250
);
255251
}
252+
253+
@override
254+
String get runtimeTypeName => 'AmplifyDataStore';
256255
}
257256

258257
class _NativeAmplifyAuthCognito

0 commit comments

Comments
 (0)