Skip to content

Commit 16d665f

Browse files
Dillon Nysdnys1
authored andcommitted
Clean up
1 parent ed53a02 commit 16d665f

File tree

8 files changed

+61
-57
lines changed

8 files changed

+61
-57
lines changed

packages/amplify_authenticator/lib/amplify_authenticator.dart

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -578,20 +578,12 @@ class _AuthenticatorState extends State<Authenticator> {
578578
}
579579

580580
Future<void> _waitForConfiguration() async {
581-
try {
582-
final config = await Amplify.asyncConfig;
583-
setState(() {
584-
_config = config;
585-
_configInitialized = true;
586-
_missingConfigValues = missingConfigValues(config);
587-
});
588-
} on Exception catch (e) {
589-
_showExceptionBanner(
590-
type: StatusType.error,
591-
message: AuthenticatorException(e).message,
592-
);
593-
await _waitForConfiguration();
594-
}
581+
final config = await Amplify.asyncConfig;
582+
setState(() {
583+
_config = config;
584+
_configInitialized = true;
585+
_missingConfigValues = missingConfigValues(config);
586+
});
595587
}
596588

597589
List<String> missingConfigValues(AmplifyConfig? config) {

packages/amplify_core/lib/amplify_core.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export 'src/types/exception/amplify_already_configured_exception.dart';
8686
export 'src/types/exception/amplify_exception.dart';
8787
export 'src/types/exception/amplify_exception_messages.dart';
8888
export 'src/types/exception/codegen_exception.dart';
89-
export 'src/types/exception/configuration_exception.dart';
89+
export 'src/types/exception/configuration_error.dart';
9090
export 'src/types/exception/url_launcher_exception.dart';
9191

9292
/// Model-based types used in datastore and API

packages/amplify_core/lib/src/amplify_class.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,24 @@ abstract class AmplifyClass {
9595
try {
9696
final json = jsonDecode(configuration) as Map;
9797
amplifyConfig = AmplifyConfig.fromJson(json.cast());
98-
} on Object catch (e) {
99-
throw ConfigurationException(
100-
'The provided configuration is not a valid json. Check underlyingException.',
98+
} on Object {
99+
throw ConfigurationError(
100+
'The provided configuration is not a valid json. '
101+
'Check underlyingException.',
101102
recoverySuggestion:
102-
'Inspect your amplifyconfiguration.dart and ensure that the string is proper json',
103-
underlyingException: e,
103+
'Inspect your amplifyconfiguration.dart and ensure that '
104+
'the string is proper json',
104105
);
105106
}
106107
await configurePlatform(configuration);
107108
_configCompleter.complete(amplifyConfig);
108-
} on ConfigurationException catch (e, st) {
109+
} on ConfigurationError catch (e, st) {
109110
// Complete with the configuration error and reset the completer so
110111
// that 1) `configure` can be called again and 2) listeners registered
111112
// on `asyncConfig` are notified of the error so they can handle it as
112113
// appropriate. For example, the Authenticator listens for `asyncConfig`
113114
// to complete before updating the UI.
114115
_configCompleter.completeError(e, st);
115-
_configCompleter = Completer();
116116
rethrow;
117117
} on Object {
118118
// At this point, configuration is complete in the sense that the
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
/// {@template amplify_core.exceptions.configuration_error}
16+
/// An error occurring during configuration of an Amplify plugin, typically
17+
/// the result of missing values needed for that plugin to function properly.
18+
///
19+
/// This is a non-recoverable error only thrown during the call to
20+
/// `Amplify.configure`. If that call succeeds, developers do not need to worry
21+
/// about future configuration errors.
22+
/// {@endtemplate}
23+
class ConfigurationError extends Error {
24+
/// {@macro amplify_core.exceptions.configuration_error}
25+
ConfigurationError(
26+
this.message, {
27+
this.recoverySuggestion,
28+
});
29+
30+
/// A description of the error.
31+
final String message;
32+
33+
/// Details on how to fix the issue, if available.
34+
final String? recoverySuggestion;
35+
36+
@override
37+
String toString() {
38+
return 'ConfigurationError($message${recoverySuggestion == null ? '' : ', $recoverySuggestion'})';
39+
}
40+
}

packages/amplify_core/lib/src/types/exception/configuration_exception.dart

Lines changed: 0 additions & 28 deletions
This file was deleted.

packages/amplify_core/test/amplify_class_test.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,23 @@ void main() {
3636
test('throws for invalid JSON', () async {
3737
expect(
3838
Amplify.asyncConfig,
39-
throwsA(isA<ConfigurationException>()),
39+
throwsA(isA<ConfigurationError>()),
4040
);
4141
expect(
4242
Amplify.configure('...'),
43-
throwsA(isA<ConfigurationException>()),
43+
throwsA(isA<ConfigurationError>()),
4444
);
4545
});
4646

4747
test('throws for configuration exceptions', () async {
4848
expect(
4949
Amplify.asyncConfig,
50-
throwsA(isA<ConfigurationException>()),
50+
throwsA(isA<ConfigurationError>()),
5151
);
5252
await Amplify.addPlugin(ConfigErrorPlugin());
5353
expect(
5454
Amplify.configure(dummyConfiguration),
55-
throwsA(isA<ConfigurationException>()),
55+
throwsA(isA<ConfigurationError>()),
5656
);
5757
});
5858

@@ -74,7 +74,7 @@ class ConfigErrorPlugin extends AnalyticsPluginInterface {
7474
AmplifyConfig? config,
7575
required AmplifyAuthProviderRepository authProviderRepo,
7676
}) {
77-
throw const ConfigurationException('Could not configure');
77+
throw ConfigurationError('Could not configure');
7878
}
7979
}
8080

packages/auth/amplify_auth_cognito_dart/lib/src/auth_plugin_impl.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ class AmplifyAuthCognitoDart extends AuthPluginInterface<
269269
required AmplifyAuthProviderRepository authProviderRepo,
270270
}) async {
271271
if (config == null) {
272-
throw const ConfigurationException('No Cognito plugin config detected');
272+
throw ConfigurationError('No Cognito plugin config detected');
273273
}
274274

275275
if (_stateMachine.getOrCreate(AuthStateMachine.type).currentState.type !=

packages/auth/amplify_auth_cognito_dart/lib/src/state/machines/auth_state_machine.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class AuthStateMachine extends AuthStateMachineBase {
4848
// InitializeAuthConfiguration
4949
final cognitoConfig = event.config.auth?.awsPlugin;
5050
if (cognitoConfig == null) {
51-
throw const ConfigurationException('No Cognito plugin config available');
51+
throw ConfigurationError('No Cognito plugin config available');
5252
}
5353
addInstance(cognitoConfig);
5454
final config = AuthConfiguration.fromConfig(cognitoConfig);

0 commit comments

Comments
 (0)