diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Legacy/Router/AuthRouter.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Legacy/Router/AuthRouter.swift index 5aa91722..11778c72 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Legacy/Router/AuthRouter.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Legacy/Router/AuthRouter.swift @@ -19,7 +19,9 @@ enum AuthRouter { } extension AuthRouter: BaseTargetType { - var headers: Parameters? { + + + var headers: [String : String]? { switch self { case .socialLogin: return APIHeaders.hasSocialTokenHeader diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Base/BaseService.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Base/BaseService.swift index 0aa6e496..eef7f034 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Base/BaseService.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Base/BaseService.swift @@ -46,7 +46,7 @@ final class BaseService { extension BaseService { /// 네트워크 응답 처리 메소드 private func fetchResponse(with target: API) -> AnyPublisher { - return requestHandler.executeRequest(for: target) + return requestHandler.executeRequest(for: target, isWithInterceptor: target.isWithInterceptor) .handleEvents(receiveSubscription: { _ in NetworkLogHandler.requestLogging(target) }, receiveOutput: { response in diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Base/NetworkLogHandler.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Base/NetworkLogHandler.swift index e6985ec5..e38b0402 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Base/NetworkLogHandler.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Base/NetworkLogHandler.swift @@ -15,7 +15,7 @@ struct NetworkLogHandler { let url = endpoint.url + (endpoint.path ?? "") let method = endpoint.method.rawValue let headers = endpoint.headers ?? [:] - let parameters = endpoint.parameters ?? [:] + let parameters = endpoint.task print(""" ================== 📤 Request ===================> diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Interceptor/TokenInterceptor.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Interceptor/TokenInterceptor.swift index 0b810b90..6977a262 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Interceptor/TokenInterceptor.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Interceptor/TokenInterceptor.swift @@ -7,6 +7,7 @@ // import Foundation +import Combine struct TokenInterceptor { @@ -21,16 +22,20 @@ struct TokenInterceptor { } - func adapt( - _ request: URLRequest - ) async throws -> URLRequest { - return request - } - - - func retry( - for session: URLSession - ) async throws { - - } + func adapt(_ request: URLRequest) -> AnyPublisher { + // 여기에 필요한 로직을 추가하여 request를 수정할 수 있습니다. + return Just(request) + .setFailureType(to: HMHNetworkError.self) // 성공 시 반환될 값의 타입 설정 + .eraseToAnyPublisher() // AnyPublisher로 반환 + } + + + func retry(for session: URLSession) -> AnyPublisher { + // 여기에 retry 로직을 추가합니다. + return Future { promise in + // retry 로직을 구현하여 promise를 성공 또는 실패로 완료합니다. + // 예: promise(.success(())) 또는 promise(.failure(error)) + } + .eraseToAnyPublisher() // AnyPublisher로 반환 + } } diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Request/Builder/RequestHandler.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Request/Builder/RequestHandler.swift index ab4f0df9..f060b09d 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Request/Builder/RequestHandler.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Request/Builder/RequestHandler.swift @@ -29,17 +29,14 @@ class RequestHandler { .mapError { ErrorHandler.handleError(target, error: .invalidRequest($0)) } .flatMap { urlRequest in if isWithInterceptor { - return TokenInterceptor - .catch { error in - // Adapt 실패 시 에러 처리 - Just(urlRequest) // 원래 요청을 반환 - .setFailureType(to: HMHNetworkError.RequestError.self) - } + return TokenInterceptor.shared.adapt(urlRequest) } else { return Just(urlRequest) - .setFailureType(to: HMHNetworkError.RequestError.self) + .setFailureType(to: HMHNetworkError.self) + .eraseToAnyPublisher() } } + .map { $0 } .flatMap { urlRequest in self.session.dataTaskPublisher(for: urlRequest) .tryMap { data, response -> NetworkResponse in diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Request/Builder/URLRequestTargetType.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Request/Builder/URLRequestTargetType.swift index a86c0b21..7b8ac9d5 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Request/Builder/URLRequestTargetType.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Request/Builder/URLRequestTargetType.swift @@ -15,6 +15,7 @@ protocol URLRequestTargetType { var method: HTTPMethod { get } var headers : [String : String]? { get } var task: Task { get } + var isWithInterceptor: Bool { get } func asURLRequest() -> AnyPublisher } diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Request/Config/APIHeaders.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Request/Config/APIHeaders.swift index 5b31386e..64abee6d 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Request/Config/APIHeaders.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Foundation/Request/Config/APIHeaders.swift @@ -32,6 +32,10 @@ public struct APIHeaders { } public extension APIHeaders { + static var noTokenHeader: Dictionary { + [contentType: applicationJSON] + } + static var hasSocialTokenHeader: [String: String] { return [contentType: applicationJSON, auth: appleAccessToken] diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Service/Auth/AuthAPI.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Service/Auth/AuthAPI.swift index 6e08a28a..17573868 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Service/Auth/AuthAPI.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Service/Auth/AuthAPI.swift @@ -17,6 +17,10 @@ enum AuthAPI { } extension AuthAPI: BaseAPI { + var isWithInterceptor: Bool { + return false + } + var path: String? { switch self { case .signUp: diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Service/Challenge/ChallengeAPI.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Service/Challenge/ChallengeAPI.swift index 9e51bbe2..eedd208c 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Service/Challenge/ChallengeAPI.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Service/Challenge/ChallengeAPI.swift @@ -21,6 +21,10 @@ enum ChallengeAPI { } extension ChallengeAPI: BaseAPI { + var isWithInterceptor: Bool { + return true + } + var path: String? { switch self { case .createChallenge: diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Service/Point/PointAPI.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Service/Point/PointAPI.swift index c208c791..736b9689 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Service/Point/PointAPI.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Service/Point/PointAPI.swift @@ -19,6 +19,10 @@ enum PointAPI { } extension PointAPI: BaseAPI { + var isWithInterceptor: Bool { + return false + } + var path: String? { switch self { case .getUsagePoint: diff --git a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Service/User/UserAPI.swift b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Service/User/UserAPI.swift index e8fee33c..ad07fae0 100644 --- a/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Service/User/UserAPI.swift +++ b/HMH_Tuist_iOS/Projects/Modules/Networks/Sources/Refactor/Service/User/UserAPI.swift @@ -18,6 +18,10 @@ enum UserAPI { } extension UserAPI: BaseAPI { + var isWithInterceptor: Bool { + return false + } + var path: String? { switch self { case .logout: