Skip to content
Merged
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
4 changes: 1 addition & 3 deletions FirebaseFunctions/Sources/Functions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,8 @@ enum FunctionsConstants {
private func callableResult(fromResponseData data: Data) throws -> HTTPSCallableResult {
let processedData = try processedData(fromResponseData: data)
let json = try responseDataJSON(from: processedData)
// TODO: Refactor `decode(_:)` so it either returns a non-optional object or throws
let payload = try serializer.decode(json)
// TODO: Remove `as Any` once `decode(_:)` is refactored
return HTTPSCallableResult(data: payload as Any)
return HTTPSCallableResult(data: payload)
}

private func processedData(fromResponseData data: Data) throws -> Data {
Expand Down
7 changes: 4 additions & 3 deletions FirebaseFunctions/Sources/Internal/FunctionsSerializer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,17 @@ final class FunctionsSerializer {
}
}

func decode(_ object: Any) throws -> AnyObject? {
func decode(_ object: Any) throws -> Any {
// Return these types as is. PORTING NOTE: Moved from the bottom of the func for readability.
if let dict = object as? NSDictionary {
if let requestedType = dict["@type"] as? String {
guard let value = dict["value"] as? String else {
// Seems like we should throw here - but this maintains compatibility.
return dict
}
let result = try decodeWrappedType(requestedType, value)
if result != nil { return result }
if let result = try decodeWrappedType(requestedType, value) {
return result
}

// Treat unknown types as dictionaries, so we don't crash old clients when we add types.
}
Expand Down
Loading