Skip to content

Commit

Permalink
feature: offer response code, body when responseDataIsNotDecodable error
Browse files Browse the repository at this point in the history
  • Loading branch information
0xWOF committed Jan 19, 2024
1 parent 2497b46 commit 01688f2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Source/Network/Implement/Client/JSONClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ extension JSONClient {
)
.then { code2XX, data -> ClientResult<JSON> in
guard let data, let body = try? JSON.parse(data) else {
throw JSONClientError.responseDataIsNotDecodable
throw JSONClientError.responseDataIsNotDecodable(code: code2XX, data: data)
}


Expand All @@ -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)
}
Expand All @@ -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?)
}

0 comments on commit 01688f2

Please sign in to comment.