From eeecf6bd25343466e619390d66739ebe0a926148 Mon Sep 17 00:00:00 2001 From: Subeom Choi Date: Fri, 19 Jan 2024 18:42:43 +0900 Subject: [PATCH] fix: solve issue that nil body throw bodyIsNotEncodable error --- Source/Network/Implement/Client/JSONClient.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Source/Network/Implement/Client/JSONClient.swift b/Source/Network/Implement/Client/JSONClient.swift index 8b44a0d..86c230c 100644 --- a/Source/Network/Implement/Client/JSONClient.swift +++ b/Source/Network/Implement/Client/JSONClient.swift @@ -38,15 +38,19 @@ extension JSONClient { timeout: Interval? = nil, optionBlock: (inout URLRequest) -> Void = { _ in } ) -> Promise, 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 )