Skip to content

Commit 205c50f

Browse files
[google_sign_in] Add GoogleSignInExceptionCode export (#9545)
`GoogleSignInException` and `GoogleSignInExceptionCode` were both intended to be exported to clients to allow for structured error handling, but the latter was missed. This adds the missing export, as well as example usage in the example app (which would have caught the mistake). Fixes flutter/flutter#171462 ## Pre-Review Checklist [^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
1 parent 495beb2 commit 205c50f

File tree

4 files changed

+20
-5
lines changed

4 files changed

+20
-5
lines changed

packages/google_sign_in/google_sign_in/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 7.1.0
2+
3+
* Adds the missing export of `GoogleSignInExceptionCode`, to allow for
4+
structured error handling as intended by the API.
5+
16
## 7.0.0
27

38
* **BREAKING CHANGE**: Many APIs have changed or been replaced to reflect the

packages/google_sign_in/google_sign_in/example/lib/main.dart

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class _SignInDemoState extends State<SignInDemo> {
109109
_currentUser = null;
110110
_isAuthorized = false;
111111
_errorMessage = e is GoogleSignInException
112-
? 'GoogleSignInException ${e.code}: ${e.description}'
112+
? _errorMessageFromSignInException(e)
113113
: 'Unknown error: $e';
114114
});
115115
}
@@ -208,7 +208,7 @@ class _SignInDemoState extends State<SignInDemo> {
208208
});
209209
unawaited(_handleGetContact(_currentUser!));
210210
} on GoogleSignInException catch (e) {
211-
_errorMessage = 'GoogleSignInException ${e.code}: ${e.description}';
211+
_errorMessage = _errorMessageFromSignInException(e);
212212
}
213213
}
214214

@@ -228,7 +228,7 @@ class _SignInDemoState extends State<SignInDemo> {
228228
_serverAuthCode = serverAuth == null ? '' : serverAuth.serverAuthCode;
229229
});
230230
} on GoogleSignInException catch (e) {
231-
_errorMessage = 'GoogleSignInException ${e.code}: ${e.description}';
231+
_errorMessage = _errorMessageFromSignInException(e);
232232
}
233233
}
234234

@@ -335,4 +335,14 @@ class _SignInDemoState extends State<SignInDemo> {
335335
child: _buildBody(),
336336
));
337337
}
338+
339+
String _errorMessageFromSignInException(GoogleSignInException e) {
340+
// In practice, an application should likely have specific handling for most
341+
// or all of the, but for simplicity this just handles cancel, and reports
342+
// the rest as generic errors.
343+
return switch (e.code) {
344+
GoogleSignInExceptionCode.canceled => 'Sign in canceled',
345+
_ => 'GoogleSignInException ${e.code}: ${e.description}',
346+
};
347+
}
338348
}

packages/google_sign_in/google_sign_in/lib/google_sign_in.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import 'src/identity_types.dart';
1212
import 'src/token_types.dart';
1313

1414
export 'package:google_sign_in_platform_interface/google_sign_in_platform_interface.dart'
15-
show GoogleSignInException;
15+
show GoogleSignInException, GoogleSignInExceptionCode;
1616
export 'src/event_types.dart';
1717
export 'src/identity_types.dart';
1818
export 'src/token_types.dart';

packages/google_sign_in/google_sign_in/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for Google Sign-In, a secure authentication system
33
for signing in with a Google account.
44
repository: https://github.com/flutter/packages/tree/main/packages/google_sign_in/google_sign_in
55
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+google_sign_in%22
6-
version: 7.0.0
6+
version: 7.1.0
77

88
environment:
99
sdk: ^3.6.0

0 commit comments

Comments
 (0)