Skip to content

Commit

Permalink
fix(datastore): hot restart
Browse files Browse the repository at this point in the history
Ignore platform exceptions so that authenticator no longer freezes app with datastore on hot restart.
  • Loading branch information
kyle committed Aug 1, 2023
1 parent 86d086c commit 76a11ef
Showing 1 changed file with 9 additions and 21 deletions.
30 changes: 9 additions & 21 deletions packages/amplify_datastore/lib/amplify_datastore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import 'package:meta/meta.dart';
export 'package:amplify_core/src/types/datastore/datastore_types.dart'
hide DateTimeParse;

class AmplifyDataStore extends DataStorePluginInterface {
class AmplifyDataStore extends DataStorePluginInterface
with AWSDebuggable, AmplifyLoggerMixin {
/// Constructs an AmplifyDataStore plugin with mandatory [modelProvider]
/// and optional datastore configuration properties including
///
Expand Down Expand Up @@ -77,16 +78,9 @@ class AmplifyDataStore extends DataStorePluginInterface {
} on PlatformException catch (e) {
if (e.code.contains('AmplifyAlreadyConfiguredException') ||
e.code.contains('AlreadyConfiguredException')) {
throw const AmplifyAlreadyConfiguredException(
AmplifyExceptionMessages.alreadyConfiguredDefaultMessage,
recoverySuggestion:
AmplifyExceptionMessages.alreadyConfiguredDefaultSuggestion,
);
logger.info('Ignoring Amplify Native already configured exception');
}
throw ConfigurationError(
e.message ?? 'An unknown error occurred',
underlyingException: e,
);
return;
}
// Update the native cache for the current user on hub events.
Future<void> updateCurrentUser(AuthUser? currentUser) async {
Expand Down Expand Up @@ -128,17 +122,7 @@ class AmplifyDataStore extends DataStorePluginInterface {
await nativeBridge.addApiPlugin(authProvidersList);
} on PlatformException catch (e) {
if (e.code.contains('AmplifyAlreadyConfiguredException') ||
e.code.contains('AlreadyConfiguredException')) {
throw const AmplifyAlreadyConfiguredException(
AmplifyExceptionMessages.alreadyConfiguredDefaultMessage,
recoverySuggestion:
AmplifyExceptionMessages.alreadyConfiguredDefaultSuggestion,
);
}
throw ConfigurationError(
e.message ?? 'An unknown error occurred',
underlyingException: e,
);
e.code.contains('AlreadyConfiguredException')) {}
}
}

Expand All @@ -154,6 +138,7 @@ class AmplifyDataStore extends DataStorePluginInterface {
Map<String, String>.from(e.details as Map),
);
} else if (e.code == 'AmplifyAlreadyConfiguredException') {
logger.info('Ignoring Amplify Native already configured exception');
return;
} else {
// This shouldn't happen. All exceptions coming from platform for
Expand Down Expand Up @@ -253,6 +238,9 @@ class AmplifyDataStore extends DataStorePluginInterface {
throttleOptions: throttleOptions,
);
}

@override
String get runtimeTypeName => 'AmplifyDataStore';
}

class _NativeAmplifyAuthCognito
Expand Down

0 comments on commit 76a11ef

Please sign in to comment.