Skip to content

Commit

Permalink
fix: error catching
Browse files Browse the repository at this point in the history
  • Loading branch information
bigearsenal committed May 18, 2023
1 parent 5e60c88 commit fdbc1a8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
8 changes: 4 additions & 4 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/p2p-org/OrcaSwapSwift.git",
"state": {
"branch": null,
"revision": "409ceb7c1bf2fe70d8bf29011fe1c2f641a1f552",
"version": "3.0.0"
"revision": "c15012e45f18cc8e553efaa1d24e34a57c99d274",
"version": "3.0.1"
}
},
{
Expand All @@ -24,8 +24,8 @@
"repositoryURL": "https://github.com/p2p-org/solana-swift.git",
"state": {
"branch": null,
"revision": "c8bead282faabbd68cfb90e2bae0da461c2f7635",
"version": "3.0.0"
"revision": "fcf4b389a3b3f1e0968748385b92203e24dd1fc2",
"version": "3.0.1"
}
},
{
Expand Down
24 changes: 22 additions & 2 deletions Sources/FeeRelayerSwift/APIClient/Networking/HTTPClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,13 @@ public final class FeeRelayerHTTPClient: HTTPClient {
.first?
.RpcResponseError
{
throw SolanaSwift.APIClientError.responseError(responseError)
throw SolanaSwift.APIClientError.responseError(
.init(
code: responseError.code,
message: responseError.message,
data: .init(logs: responseError.data?.RpcSimulateTransactionResult?.logs)
)
)
}
}

Expand Down Expand Up @@ -111,6 +117,20 @@ private struct CustomError: Decodable {
let ClientError: [_ClientError]

struct _ClientError: Decodable {
let RpcResponseError: SolanaSwift.ResponseError
let RpcResponseError: _RpcResponseError

struct _RpcResponseError: Decodable {
let code: Int?
let message: String?
let data: _RpcResponseErrorData?

struct _RpcResponseErrorData: Decodable {
let RpcSimulateTransactionResult: _RpcSimulateTransactionResult?

struct _RpcSimulateTransactionResult: Decodable {
let logs: [String]?
}
}
}
}
}
4 changes: 2 additions & 2 deletions Sources/FeeRelayerSwift/Models/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ public struct FeeRelayerError: Swift.Error, Decodable, Equatable {
.init(code: -11, message: "Unauthorized", data: nil)
}

public static var topUpSuccessButTransactionThrows: Self {
.init(code: -12, message: "Topping up is successfull, but the transaction failed", data: nil)
public static func topUpSuccessButTransactionThrows(logs: [String]?) -> Self {
.init(code: -12, message: "Topping up is successfull, but the transaction failed", data: .init(type: .clientError, data: .init(array: logs)))
}

public static var inconsistenceRelayContext: Self {
Expand Down
9 changes: 8 additions & 1 deletion Sources/FeeRelayerSwift/Relay/Service/RelayServiceImpl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,14 @@ public class RelayServiceImpl: RelayService {
return trx
} catch {
if toppedUp {
throw FeeRelayerError.topUpSuccessButTransactionThrows
let responseError: SolanaSwift.ResponseError?
switch error {
case SolanaSwift.APIClientError.responseError(let detail):
responseError = detail
default:
responseError = nil
}
throw FeeRelayerError.topUpSuccessButTransactionThrows(logs: responseError?.data?.logs)
}
throw error
}
Expand Down

0 comments on commit fdbc1a8

Please sign in to comment.