Skip to content

Commit

Permalink
change response
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzh committed Jun 8, 2022
1 parent 3bc3858 commit 9b83bd7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions ApiParser/Sources/ApiParser/CodeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,9 @@ extension CodeGenerator {
} else {
result.append("\(tab)\(property.accessType) var \(property.name): \(property.type)\n")
}
if property.name == "message" {
result.append("\(tab)public var localizedDescription: String { self.message }\n")
}
}
result.append("\n\(tab)public init(")
for (index, property) in swiftStruct.properties.enumerated() {
Expand Down
10 changes: 8 additions & 2 deletions Sources/EverscaleClientSwift/Binding/BindingTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public struct TSDKBindingResponse<TSDKResult: Codable, TSDKError: Codable> {
public var error: TSDKError?
public var finished: Bool = false
public var requestId: UInt32 = 0
public var rawResponse: String?
public var rawResponse: String = .init()

public mutating func update(_ requestId: UInt32,
_ rawResponse: String,
Expand All @@ -63,8 +63,14 @@ public struct TSDKBindingResponse<TSDKResult: Codable, TSDKError: Codable> {
case .responseError:
error = rawResponse.toModel(TSDKError.self)
Log.warn(error ?? "RESPONSE TYPE ERROR, BUT ERROR IS NIL")
default:
case .responseCustom:
result = rawResponse.toModel(TSDKResult.self)
case .responseNop:
// result = rawResponse.toModel(TSDKResult.self)
break
default:
error = rawResponse.toModel(TSDKError.self)
Log.warn(error ?? "responseType NOT FOUND and TSDKError not parsed")
}
}
}
4 changes: 2 additions & 2 deletions Tests/EverscaleClientSwiftTests/NetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ final class NetTests: XCTestCase {
BindingStore.deleteResponseHandler(response.requestId)
group.leave()
return
} else if let result = response.rawResponse?.toModel(TSDKDefault.self)?.result?.toAny() as? [String: Any],
} else if let result = response.rawResponse.toModel(TSDKDefault.self)?.result?.toAny() as? [String: Any],
let account_addr = result["account_addr"]
{
XCTAssertTrue((account_addr as? String) != nil)
}
if response.finished || response.rawResponse != nil {
if response.finished {
BindingStore.deleteResponseHandler(response.requestId)
group.leave()
}
Expand Down

0 comments on commit 9b83bd7

Please sign in to comment.