Skip to content

Fix error generation when status is .internal #11311

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 3 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
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
8 changes: 4 additions & 4 deletions FirebaseFunctions/Tests/Integration/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
}
}
Expand All @@ -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
}
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)
XCTAssertNotEqual("INTERNAL", 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);
XCTAssertNotEqualObjects(@"INTERNAL", error.localizedDescription);
[expectation fulfill];
}];
[self waitForExpectations:@[ expectation ] timeout:10];
Expand Down