Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit a252bf3

Browse files
yuwen-yanmehmetf
authored andcommitted
[google_sign_in] Expose network error (#2398)
1 parent 4150876 commit a252bf3

File tree

5 files changed

+17
-3
lines changed

5 files changed

+17
-3
lines changed

packages/google_sign_in/google_sign_in/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 4.1.2
2+
3+
* Added a new error code `network_error`, and return it when a network error occurred.
4+
15
## 4.1.1
26

37
* Support passing `clientId` to the web plugin programmatically.

packages/google_sign_in/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ public static final class Delegate implements IDelegate, PluginRegistry.Activity
173173
// These error codes must match with ones declared on iOS and Dart sides.
174174
private static final String ERROR_REASON_SIGN_IN_CANCELED = "sign_in_canceled";
175175
private static final String ERROR_REASON_SIGN_IN_REQUIRED = "sign_in_required";
176+
private static final String ERROR_REASON_NETWORK_ERROR = "network_error";
176177
private static final String ERROR_REASON_SIGN_IN_FAILED = "sign_in_failed";
177178
private static final String ERROR_FAILURE_TO_RECOVER_AUTH = "failed_to_recover_auth";
178179
private static final String ERROR_USER_RECOVERABLE_AUTH = "user_recoverable_auth";
@@ -372,6 +373,8 @@ private String errorCodeForStatus(int statusCode) {
372373
return ERROR_REASON_SIGN_IN_CANCELED;
373374
} else if (statusCode == CommonStatusCodes.SIGN_IN_REQUIRED) {
374375
return ERROR_REASON_SIGN_IN_REQUIRED;
376+
} else if (statusCode == CommonStatusCodes.NETWORK_ERROR) {
377+
return ERROR_REASON_NETWORK_ERROR;
375378
} else {
376379
return ERROR_REASON_SIGN_IN_FAILED;
377380
}

packages/google_sign_in/google_sign_in/ios/Classes/FLTGoogleSignInPlugin.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// These error codes must match with ones declared on Android and Dart sides.
1414
static NSString *const kErrorReasonSignInRequired = @"sign_in_required";
1515
static NSString *const kErrorReasonSignInCanceled = @"sign_in_canceled";
16+
static NSString *const kErrorReasonNetworkError = @"network_error";
1617
static NSString *const kErrorReasonSignInFailed = @"sign_in_failed";
1718

1819
static FlutterError *getFlutterError(NSError *error) {
@@ -21,6 +22,8 @@
2122
errorCode = kErrorReasonSignInRequired;
2223
} else if (error.code == kGIDSignInErrorCodeCanceled) {
2324
errorCode = kErrorReasonSignInCanceled;
25+
} else if ([error.domain isEqualToString:NSURLErrorDomain]) {
26+
errorCode = kErrorReasonNetworkError;
2427
} else {
2528
errorCode = kErrorReasonSignInFailed;
2629
}

packages/google_sign_in/google_sign_in/lib/google_sign_in.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ class GoogleSignIn {
195195
/// user.
196196
static const String kSignInCanceledError = 'sign_in_canceled';
197197

198+
/// Error code indicating network error. Retrying should resolve the problem.
199+
static const String kNetworkError = 'network_error';
200+
198201
/// Error code indicating that attempt to sign in failed.
199202
static const String kSignInFailedError = 'sign_in_failed';
200203

@@ -314,8 +317,9 @@ class GoogleSignIn {
314317
///
315318
/// When [suppressErrors] is set to `false` and an error occurred during sign in
316319
/// returned Future completes with [PlatformException] whose `code` can be
317-
/// either [kSignInRequiredError] (when there is no authenticated user) or
318-
/// [kSignInFailedError] (when an unknown error occurred).
320+
/// one of [kSignInRequiredError] (when there is no authenticated user) ,
321+
/// [kNetworkError] (when a network error occurred) or [kSignInFailedError]
322+
/// (when an unknown error occurred).
319323
Future<GoogleSignInAccount> signInSilently({
320324
bool suppressErrors = true,
321325
}) async {

packages/google_sign_in/google_sign_in/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: google_sign_in
22
description: Flutter plugin for Google Sign-In, a secure authentication system
33
for signing in with a Google account on Android and iOS.
44
homepage: https://github.com/flutter/plugins/tree/master/packages/google_sign_in/google_sign_in
5-
version: 4.1.1
5+
version: 4.1.2
66

77
flutter:
88
plugin:

0 commit comments

Comments
 (0)