From d1082cce876c775c9941ea5e80c378741a96a4d2 Mon Sep 17 00:00:00 2001 From: mino Date: Thu, 30 Nov 2023 11:15:10 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20resume=20=EB=82=B4=EB=B6=80=20?= =?UTF-8?q?=EB=B6=84=EA=B8=B0=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/CuteNetwork/Cute.swift | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Sources/CuteNetwork/Cute.swift b/Sources/CuteNetwork/Cute.swift index ffe8594..7d8f73a 100644 --- a/Sources/CuteNetwork/Cute.swift +++ b/Sources/CuteNetwork/Cute.swift @@ -32,13 +32,25 @@ class Cute: NSObject, NetworkRouter, URLSessionDelegate return try await withCheckedThrowingContinuation({ value in petit(root, logAccess: petitLogVisible) { data, response, error in if let error { - value.resume(throwing: error) - } else if let data { - value.resume(returning: data) - } else { - value.resume(throwing: NetworkError.noData) + value.resume(throwing: error as? NetworkError ?? NetworkError.custom(message: error.localizedDescription)) } + if let response = response as? HTTPURLResponse { + let result = ResponseHandler.handleNetworkResponse(response) + switch result { + case .success: + guard let data else { + value.resume(throwing: NetworkError.custom(message: "데이터를 받지 못했습니다.")) + return + } + value.resume(returning: data) + case .failure(let message): + guard let _ = data else { + value.resume(throwing: NetworkError.custom(message: message)) + return + } + } + } } }) }