Skip to content

Update tests for exposing internal error description #11322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion FirebaseFunctions/Backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
});
});
Expand Down
3 changes: 3 additions & 0 deletions FirebaseFunctions/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
14 changes: 7 additions & 7 deletions FirebaseFunctions/Sources/FunctionsError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions FirebaseFunctions/Tests/Integration/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down