Open
Description
Description
Thanks to #14280, we can now receive the HttpsError from Blocking Functions.However, we still cannot obtain any information beyond the HttpsError.message
.For example, fields such as HttpsError.code
and HttpsError.details
remain unavailable. It would be preferable to retrieve all error details, similar to what the Android SDK offers.
Suggested Fix
The current code only retrieves HttpsError.message
from the server response.
firebase-ios-sdk/FirebaseAuth/Sources/Swift/Utilities/AuthErrorUtils.swift
Lines 563 to 573 in b888e1e
To include all HttpsError
information, set it in userInfo.
static func blockingCloudFunctionServerResponse(message: String?) -> Error {
guard let message else {
return error(code: .blockingCloudFunctionError, message: message)
}
guard let jsonDict = extractJSONObjectFromString(from: message) else {
return error(code: .blockingCloudFunctionError, message: message)
}
let httpsError = jsonDict["error"] as? [String: Any] ?? [:]
var userInfo: [String: Any] = [:]
userInfo[AuthErrors.userInfoBlockingFunctionHttpErrorKey] = httpsError
let errorMessage = httpsError["message"] as? String
userInfo[NSLocalizedDescriptionKey] = errorMessage // ※ For backwards compatible
return error(code: .blockingCloudFunctionError, userInfo: userInfo)
}
Reproducing the issue
- Throw below httpsError in your beforeUserCreated Blocking Cloud Function (can be any blocking function)
https_fn.HttpsError( code=https_fn.FunctionsErrorCode.UNAUTHENTICATED, message="authentication failed", details= { "type": "mfa", }, )
- Create a user in the swift app and catch the error, here's an example code
do { try await Auth.auth().createUser(withEmail: email, password: password) } catch { print("\(error)") }
- You catch below error and this error do not contain
HttpsError.code
orHttpsError.details
Error Domain=FIRAuthErrorDomain Code=17105 "authentication failed" UserInfo={NSLocalizedDescription=authentication failed, FIRAuthErrorUserInfoNameKey=ERROR_BLOCKING_CLOUD_FUNCTION_RETURNED_ERROR}
- In Android SDK, you can catch error including
HttpsError.code
(status) andHttpsError.details
BLOCKING_FUNCTION_ERROR_RESPONSE:HTTP Cloud Function returned an error: {"error":{"details":{"type":"mfa"},"message":"authentication failed","status":"UNAUTHENTICATED"}}
- You catch below error and this error do not contain
Firebase SDK Version
11.8.1
Xcode Version
16.2
Installation Method
Swift Package Manager
Firebase Product(s)
Authentication, Cloud Function
Targeted Platforms
iOS