Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,40 @@ + (FlutterError *)convertToFlutterError:(NSError *)error {
return [FlutterError errorWithCode:code message:message details:additionalData];
}

+ (FlutterError *)convertAppleAuthorizationErrorToFlutterError:(NSError *)error {
NSString *message = @"An unknown error has occurred.";
if (error.localizedDescription.length > 0) {
message = error.localizedDescription;
}

NSMutableDictionary *additionalData = [NSMutableDictionary dictionary];
NSString *nativeErrorDomain = error.domain ?: @"unknown";
NSNumber *nativeErrorCode = @((long)error.code);

additionalData[@"nativeErrorDomain"] = nativeErrorDomain;
additionalData[@"nativeErrorCode"] = nativeErrorCode;

NSError *underlyingError = error.userInfo[NSUnderlyingErrorKey];
NSString *underlyingMessage = @"";
if (underlyingError != nil) {
NSString *underlyingErrorDomain = underlyingError.domain ?: @"unknown";
NSNumber *underlyingErrorCode = @((long)underlyingError.code);

additionalData[@"underlyingNativeErrorDomain"] = underlyingErrorDomain;
additionalData[@"underlyingNativeErrorCode"] = underlyingErrorCode;

underlyingMessage =
[NSString stringWithFormat:@", Underlying Domain=%@ Code=%ld", underlyingErrorDomain,
(long)underlyingError.code];
}

NSString *detailMessage =
[NSString stringWithFormat:@"%@ (Domain=%@ Code=%ld%@)", message, nativeErrorDomain,
(long)error.code, underlyingMessage];

return [FlutterError errorWithCode:@"unknown" message:detailMessage details:additionalData];
}

+ (id)getNSDictionaryFromAuthCredential:(FIRAuthCredential *)authCredential {
if (authCredential == nil) {
return [NSNull null];
Expand Down Expand Up @@ -532,7 +566,7 @@ - (void)authorizationController:(ASAuthorizationController *)controller

case ASAuthorizationErrorUnknown:
default:
completion(nil, [FLTFirebaseAuthPlugin convertToFlutterError:error]);
completion(nil, [FLTFirebaseAuthPlugin convertAppleAuthorizationErrorToFlutterError:error]);
break;
}
}
Expand Down
Loading