Skip to content

Commit

Permalink
fix respond errors
Browse files Browse the repository at this point in the history
  • Loading branch information
nerzh committed Sep 17, 2022
1 parent 7678d23 commit a0618d1
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 12 deletions.
8 changes: 4 additions & 4 deletions ApiParser/Sources/ApiParser/CodeGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ extension CodeGenerator {
result.append("\(tab)\(property.accessType) var \(property.name): \(property.type)\n")
}
if property.name == "message" {
result.append("\(tab)public var errorDescription: String { self.message }\n")
result.append("\(tab)public var failureReason: String { self.message }\n")
result.append("\(tab)public var recoverySuggestion: String { self.message }\n")
result.append("\(tab)public var helpAnchor: String { self.message }\n")
result.append("\(tab)public var errorDescription: String? { self.message }\n")
result.append("\(tab)public var failureReason: String? { self.message }\n")
result.append("\(tab)public var recoverySuggestion: String? { self.message }\n")
result.append("\(tab)public var helpAnchor: String? { self.message }\n")
}
}

Expand Down
7 changes: 3 additions & 4 deletions Sources/EverscaleClientSwift/Binding/Binding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,16 @@ public final class TSDKBindingModule: TSDKBindingPrtcl {
tsdkPayload,
requestId
) { (requestId: UInt32, params: TSDKString, responseType: UInt32, finished: Bool) in
let responseHandler = BindingStore.getResponseHandler(requestId)
do {
let swiftString: String = try TSDKBindingModule.convertFromTSDKString(params)
let responseType: TSDKBindingResponseType = (TSDKBindingResponseType.init(rawValue: responseType) ?? .unknown)!
let responseHandler = BindingStore.getResponseHandler(requestId)

try responseHandler?(requestId, swiftString, responseType, finished)
if finished || responseType == .responseError {
BindingStore.deleteResponseHandler(requestId)
}
try responseHandler?(requestId, swiftString, responseType, finished)
} catch {
let responseHandler = BindingStore.getResponseHandler(requestId)
BindingStore.deleteResponseHandler(requestId)
try? responseHandler?(
requestId,
Expand All @@ -130,7 +130,6 @@ public final class TSDKBindingModule: TSDKBindingPrtcl {
].toAnyValue().toJSON(),
.responseError,
true)

}
}
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/EverscaleClientSwift/Client/ClientTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ public enum TSDKAppRequestResultEnumTypes: String, Codable {
public struct TSDKClientError: Codable, LocalizedError {
public var code: UInt32
public var message: String
public var errorDescription: String { self.message }
public var failureReason: String { self.message }
public var recoverySuggestion: String { self.message }
public var helpAnchor: String { self.message }
public var errorDescription: String? { self.message }
public var failureReason: String? { self.message }
public var recoverySuggestion: String? { self.message }
public var helpAnchor: String? { self.message }
public var data: AnyValue = [:].toAnyValue()

public init(_ error: Error) {
Expand Down
42 changes: 42 additions & 0 deletions Tests/EverscaleClientSwiftTests/ErrorsTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// ErrorsTests.swift
//
//
// Created by Oleh Hudeichuk on 17.09.2022.
//

import XCTest
import class Foundation.Bundle
@testable import EverscaleClientSwift
@testable import CTonSDK

final class ErrorsTests: XCTestCase {

func testClientError() throws {
try testAsyncMethods { (client, group) in
let paramsOfQueryCollection: TSDKParamsOfQueryCollection = .init(collection: "accounts",
filter: [
"id": [
"eq": "0:b5e9240fc2d2f1ff8cbb1d1dee7fb7cae155e5f6320e585fcc685698994a19a5"
]
].toAnyValue(),
result: "boc")
group.enter()
do {
try client.net.query_collection(paramsOfQueryCollection) { [group] response in
if response.error != nil {
print("asdf YES", response.error!.localizedDescription)
group.leave()
} else {
throw TSDKClientError("FATAL ERROR")
}
}
} catch {
print("asdf YES", error.localizedDescription)
group.leave()
}
group.wait()
print("asdf", "AAA 5")
}
}
}

0 comments on commit a0618d1

Please sign in to comment.