|
591 | 591 | @"This operation is not"
|
592 | 592 | "supported in a multi-tenant context.";
|
593 | 593 |
|
| 594 | +/** @var kFIRAuthErrorMessageBlockingCloudFunctionReturnedError |
| 595 | + @brief Message for @c FIRAuthErrorCodeBlockingCloudFunctionError error code. |
| 596 | + */ |
| 597 | +static NSString *const kFIRAuthErrorMessageBlockingCloudFunctionReturnedError = |
| 598 | + @"Blocking cloud function returned an error."; |
| 599 | + |
594 | 600 | /** @var FIRAuthErrorDescription
|
595 | 601 | @brief The error descrioption, based on the error code.
|
596 | 602 | @remarks No default case so that we get a compiler warning if a new value was added to the enum.
|
|
755 | 761 | return kFIRAuthErrorMessageTenantIDMismatch;
|
756 | 762 | case FIRAuthErrorCodeUnsupportedTenantOperation:
|
757 | 763 | return kFIRAuthErrorMessageUnsupportedTenantOperation;
|
| 764 | + case FIRAuthErrorCodeBlockingCloudFunctionError: |
| 765 | + return kFIRAuthErrorMessageBlockingCloudFunctionReturnedError; |
758 | 766 | }
|
759 | 767 | }
|
760 | 768 |
|
|
922 | 930 | return @"ERROR_TENANT_ID_MISMATCH";
|
923 | 931 | case FIRAuthErrorCodeUnsupportedTenantOperation:
|
924 | 932 | return @"ERROR_UNSUPPORTED_TENANT_OPERATION";
|
| 933 | + case FIRAuthErrorCodeBlockingCloudFunctionError: |
| 934 | + return @"ERROR_BLOCKING_CLOUD_FUNCTION_RETURNED_ERROR"; |
925 | 935 | }
|
926 | 936 | }
|
927 | 937 |
|
@@ -1405,6 +1415,32 @@ + (NSError *)unsupportedTenantOperationError {
|
1405 | 1415 | return [self errorWithCode:FIRAuthInternalErrorCodeUnsupportedTenantOperation];
|
1406 | 1416 | }
|
1407 | 1417 |
|
| 1418 | ++ (NSError *)blockingCloudFunctionServerResponseWithMessage:(nullable NSString *)message { |
| 1419 | + if (message == nil) { |
| 1420 | + return [self errorWithCode:FIRAuthInternalErrorBlockingCloudFunctionError message:message]; |
| 1421 | + } |
| 1422 | + |
| 1423 | + NSString *jsonString = |
| 1424 | + [message stringByReplacingOccurrencesOfString:@"HTTP Cloud Function returned an error:" |
| 1425 | + withString:@""]; |
| 1426 | + jsonString = [jsonString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; |
| 1427 | + |
| 1428 | + NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; |
| 1429 | + NSError *jsonError; |
| 1430 | + NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonData |
| 1431 | + options:0 |
| 1432 | + error:&jsonError]; |
| 1433 | + |
| 1434 | + if (jsonError) { |
| 1435 | + return [self JSONSerializationErrorWithUnderlyingError:jsonError]; |
| 1436 | + } |
| 1437 | + |
| 1438 | + NSDictionary *errorDict = jsonDict[@"error"]; |
| 1439 | + NSString *errorMessage = errorDict[@"message"]; |
| 1440 | + |
| 1441 | + return [self errorWithCode:FIRAuthInternalErrorBlockingCloudFunctionError message:errorMessage]; |
| 1442 | +} |
| 1443 | + |
1408 | 1444 | @end
|
1409 | 1445 |
|
1410 | 1446 | NS_ASSUME_NONNULL_END
|
0 commit comments