From a0618d18788c5ba58d6fc2652724047776b8d522 Mon Sep 17 00:00:00 2001 From: nerzh Date: Sat, 17 Sep 2022 22:14:35 +0200 Subject: [PATCH] fix respond errors --- .../Sources/ApiParser/CodeGenerator.swift | 8 ++-- .../Binding/Binding.swift | 7 ++-- .../Client/ClientTypes.swift | 8 ++-- .../ErrorsTests.swift | 42 +++++++++++++++++++ 4 files changed, 53 insertions(+), 12 deletions(-) create mode 100644 Tests/EverscaleClientSwiftTests/ErrorsTests.swift diff --git a/ApiParser/Sources/ApiParser/CodeGenerator.swift b/ApiParser/Sources/ApiParser/CodeGenerator.swift index 7eaecc0..e5c4d4d 100644 --- a/ApiParser/Sources/ApiParser/CodeGenerator.swift +++ b/ApiParser/Sources/ApiParser/CodeGenerator.swift @@ -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") } } diff --git a/Sources/EverscaleClientSwift/Binding/Binding.swift b/Sources/EverscaleClientSwift/Binding/Binding.swift index 4b38f6c..3a2e3f5 100644 --- a/Sources/EverscaleClientSwift/Binding/Binding.swift +++ b/Sources/EverscaleClientSwift/Binding/Binding.swift @@ -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, @@ -130,7 +130,6 @@ public final class TSDKBindingModule: TSDKBindingPrtcl { ].toAnyValue().toJSON(), .responseError, true) - } } } diff --git a/Sources/EverscaleClientSwift/Client/ClientTypes.swift b/Sources/EverscaleClientSwift/Client/ClientTypes.swift index 1b68d06..c461abd 100644 --- a/Sources/EverscaleClientSwift/Client/ClientTypes.swift +++ b/Sources/EverscaleClientSwift/Client/ClientTypes.swift @@ -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) { diff --git a/Tests/EverscaleClientSwiftTests/ErrorsTests.swift b/Tests/EverscaleClientSwiftTests/ErrorsTests.swift new file mode 100644 index 0000000..24e149a --- /dev/null +++ b/Tests/EverscaleClientSwiftTests/ErrorsTests.swift @@ -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") + } + } +}