From 01688f2b6d1fdaf13c7ac9f518a56fd98e07a2cd Mon Sep 17 00:00:00 2001 From: Subeom Choi Date: Fri, 19 Jan 2024 18:12:43 +0900 Subject: [PATCH] feature: offer response code, body when responseDataIsNotDecodable error --- Source/Network/Implement/Client/JSONClient.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Source/Network/Implement/Client/JSONClient.swift b/Source/Network/Implement/Client/JSONClient.swift index 91cb573..51a7625 100644 --- a/Source/Network/Implement/Client/JSONClient.swift +++ b/Source/Network/Implement/Client/JSONClient.swift @@ -52,7 +52,7 @@ extension JSONClient { ) .then { code2XX, data -> ClientResult in guard let data, let body = try? JSON.parse(data) else { - throw JSONClientError.responseDataIsNotDecodable + throw JSONClientError.responseDataIsNotDecodable(code: code2XX, data: data) } @@ -67,7 +67,7 @@ extension JSONClient { } else if case DataClientError.statusCodeNot2XX(let codeNot2XX, let data) = error { guard let data, let body = try? JSON.parse(data) else { - throw JSONClientError.responseDataIsNotDecodable + throw JSONClientError.responseDataIsNotDecodable(code: codeNot2XX, data: data) } throw JSONClientError.statusCodeNot2XX(codeNot2XX: codeNot2XX, body: body) } @@ -80,5 +80,5 @@ public enum JSONClientError: Error { case statusCodeNotFound case statusCodeNot2XX(codeNot2XX: Int, body: JSON) case bodyIsNotEncodable - case responseDataIsNotDecodable + case responseDataIsNotDecodable(code: Int, data: Data?) }