diff --git a/FirebaseFunctions/Backend/index.js b/FirebaseFunctions/Backend/index.js index 00d5d725bce..0098bf4e864 100644 --- a/FirebaseFunctions/Backend/index.js +++ b/FirebaseFunctions/Backend/index.js @@ -78,7 +78,7 @@ exports.unknownErrorTest = functions.https.onRequest((request, response) => { response.status(400).send({ error: { status: 'THIS_IS_NOT_VALID', - message: 'this should be ignored', + message: 'invalid response', }, }); }); diff --git a/FirebaseFunctions/CHANGELOG.md b/FirebaseFunctions/CHANGELOG.md index c156c6daffd..2ae2e887ade 100644 --- a/FirebaseFunctions/CHANGELOG.md +++ b/FirebaseFunctions/CHANGELOG.md @@ -1,3 +1,6 @@ +# 10.11.0 +- [fixed] Provide more detail for internal errors. (#11310) + # 10.10.0 - [fixed] Fixed potential memory leak of Functions instances. (#11248) - [added] Callable functions can now opt in to using limited-use App Check diff --git a/FirebaseFunctions/Sources/FunctionsError.swift b/FirebaseFunctions/Sources/FunctionsError.swift index 6a2c52e1f74..cd205351e19 100644 --- a/FirebaseFunctions/Sources/FunctionsError.swift +++ b/FirebaseFunctions/Sources/FunctionsError.swift @@ -225,18 +225,18 @@ internal func FunctionsErrorForResponse(status: NSInteger, if let status = errorDetails["status"] as? String { code = FunctionsErrorCode.errorCode(forName: status) + if let message = errorDetails["message"] as? String { + description = message + } else { + description = code.descriptionForErrorCode + } + // If the code in the body is invalid, treat the whole response as malformed. guard code != .internal else { - return code.generatedError(userInfo: nil) + return code.generatedError(userInfo: [NSLocalizedDescriptionKey: description]) } } - if let message = errorDetails["message"] as? String { - description = message - } else { - description = code.descriptionForErrorCode - } - details = errorDetails["details"] as AnyObject? if let innerDetails = details { // Just ignore the details if there an error decoding them. diff --git a/FirebaseFunctions/Tests/Integration/IntegrationTests.swift b/FirebaseFunctions/Tests/Integration/IntegrationTests.swift index 089eafd926d..da2d420f195 100644 --- a/FirebaseFunctions/Tests/Integration/IntegrationTests.swift +++ b/FirebaseFunctions/Tests/Integration/IntegrationTests.swift @@ -498,7 +498,7 @@ class IntegrationTests: XCTestCase { } catch { let error = error as NSError XCTAssertEqual(FunctionsErrorCode.internal.rawValue, error.code) - XCTAssertEqual("INTERNAL", error.localizedDescription) + XCTAssertEqual("invalid response", error.localizedDescription) expectation.fulfill() return } @@ -528,7 +528,7 @@ class IntegrationTests: XCTestCase { } catch { let error = error as NSError XCTAssertEqual(FunctionsErrorCode.internal.rawValue, error.code) - XCTAssertEqual("INTERNAL", error.localizedDescription) + XCTAssertEqual("invalid response", error.localizedDescription) } } } diff --git a/FirebaseFunctions/Tests/ObjCIntegration/FIRIntegrationTests.m b/FirebaseFunctions/Tests/ObjCIntegration/FIRIntegrationTests.m index 124f2eb9044..a6fff65c04e 100644 --- a/FirebaseFunctions/Tests/ObjCIntegration/FIRIntegrationTests.m +++ b/FirebaseFunctions/Tests/ObjCIntegration/FIRIntegrationTests.m @@ -226,7 +226,7 @@ - (void)testUnknownError { completion:^(FIRHTTPSCallableResult *_Nullable result, NSError *_Nullable error) { XCTAssertNotNil(error); XCTAssertEqual(FIRFunctionsErrorCodeInternal, error.code); - XCTAssertEqualObjects(@"INTERNAL", error.localizedDescription); + XCTAssertEqualObjects(@"invalid response", error.localizedDescription); [expectation fulfill]; }]; [self waitForExpectations:@[ expectation ] timeout:10];