Skip to content

Commit

Permalink
fix decoding again
Browse files Browse the repository at this point in the history
  • Loading branch information
m1guelpf committed Oct 15, 2024
1 parent 2db37ba commit 1ffb131
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Sources/IDKitCore/Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public enum BridgeResponse<Response: Decodable>: Decodable {

if let errorCode = try? container.decode(AppError.self, forKey: .errorCode) {
self = .error(errorCode)
} else if let proof = try? container.decode(Response.self, forKey: .proof) {
} else if container.contains(.proof) {
let proof = try Response(from: decoder)
self = .success(proof)
} else {
throw DecodingError.dataCorrupted(.init(codingPath: [], debugDescription: "BridgeResponse doesn't match any expected type"))
Expand All @@ -96,12 +97,11 @@ public enum BridgeResponse<Response: Decodable>: Decodable {

extension BridgeResponse: Encodable where Response: Encodable {
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)

switch self {
case let .success(response):
try container.encode(response, forKey: .proof)
try response.encode(to: encoder)
case let .error(error):
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(error, forKey: .errorCode)
}
}
Expand Down

0 comments on commit 1ffb131

Please sign in to comment.