Skip to content

Commit

Permalink
fix: solve issue that can not encode json
Browse files Browse the repository at this point in the history
  • Loading branch information
0xWOF committed Jan 19, 2024
1 parent 5628e41 commit 2497b46
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions Source/Network/Implement/Client/JSONClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,18 @@ import SabyTime

public final class JSONClient: Client {
let client: DataClient
let encoder: JSONEncoder
let decoder: JSONDecoder

init(
client: DataClient,
encoder: JSONEncoder,
decoder: JSONDecoder
client: DataClient
) {
self.client = client
self.encoder = encoder
self.decoder = decoder
}
}

extension JSONClient {
public convenience init(optionBlock: (inout URLSessionConfiguration) -> Void = { _ in }) {
let client = DataClient(optionBlock: optionBlock)
let encoder = JSONEncoder()
let decoder = JSONDecoder()
self.init(client: client, encoder: encoder, decoder: decoder)
self.init(client: client)
}
}

Expand All @@ -46,7 +38,7 @@ extension JSONClient {
timeout: Interval? = nil,
optionBlock: (inout URLRequest) -> Void = { _ in }
) -> Promise<ClientResult<JSON>, Error> {
guard let body = try? self.encoder.encode(body) else {
guard let body = try? body?.datafy() else {
return Promise.rejected(JSONClientError.bodyIsNotEncodable)
}

Expand Down

0 comments on commit 2497b46

Please sign in to comment.