Skip to content

Commit

Permalink
fix: solve issue that nil body throw bodyIsNotEncodable error
Browse files Browse the repository at this point in the history
  • Loading branch information
0xWOF committed Jan 19, 2024
1 parent a4d912b commit eeecf6b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Source/Network/Implement/Client/JSONClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,19 @@ extension JSONClient {
timeout: Interval? = nil,
optionBlock: (inout URLRequest) -> Void = { _ in }
) -> Promise<ClientResult<JSON>, Error> {
guard let body = try? body?.datafy() else {
return Promise.rejected(JSONClientError.bodyIsNotEncodable)
var bodyData: Data? = nil
if let body {
guard let body = try? body.datafy() else {
return Promise.rejected(JSONClientError.bodyIsNotEncodable)
}
bodyData = body
}

return client.request(
url: url,
method: method,
header: header,
body: body,
body: bodyData,
timeout: timeout,
optionBlock: optionBlock
)
Expand Down

0 comments on commit eeecf6b

Please sign in to comment.