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..d2961b7a787 100644 --- a/FirebaseFunctions/Tests/Integration/IntegrationTests.swift +++ b/FirebaseFunctions/Tests/Integration/IntegrationTests.swift @@ -442,7 +442,7 @@ class IntegrationTests: XCTestCase { } catch { let error = error as NSError XCTAssertEqual(FunctionsErrorCode.internal.rawValue, error.code) - XCTAssertEqual("INTERNAL", error.localizedDescription) + XCTAssertNotEqual("INTERNAL", error.localizedDescription) expectation.fulfill() return } @@ -473,7 +473,7 @@ class IntegrationTests: XCTestCase { } catch { let error = error as NSError XCTAssertEqual(FunctionsErrorCode.internal.rawValue, error.code) - XCTAssertEqual("INTERNAL", error.localizedDescription) + XCTAssertNotEqual("INTERNAL", error.localizedDescription) } } } @@ -498,7 +498,7 @@ class IntegrationTests: XCTestCase { } catch { let error = error as NSError XCTAssertEqual(FunctionsErrorCode.internal.rawValue, error.code) - XCTAssertEqual("INTERNAL", error.localizedDescription) + XCTAssertNotEqual("INTERNAL", 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) + XCTAssertNotEqual("INTERNAL", error.localizedDescription) } } } diff --git a/FirebaseFunctions/Tests/ObjCIntegration/FIRIntegrationTests.m b/FirebaseFunctions/Tests/ObjCIntegration/FIRIntegrationTests.m index 124f2eb9044..320768c79f7 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); + XCTAssertNotEqualObjects(@"INTERNAL", error.localizedDescription); [expectation fulfill]; }]; [self waitForExpectations:@[ expectation ] timeout:10];