-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #4 - 코드리뷰 반영 - 불필요한 네트워크 모듈 파일 삭제
- Loading branch information
Showing
7 changed files
with
65 additions
and
128 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// | ||
// APIServiceError.swift | ||
// PPACNetwork | ||
// | ||
// Created by 장혜령 on 6/8/24. | ||
// | ||
|
||
import Foundation | ||
|
||
enum NetworkError: Error { | ||
/// encoding Error | ||
case urlEncodingError | ||
/// response Error | ||
case invalidResponse | ||
/// statucCode 400 ~ 499 error | ||
case clientError(statusCode: Int, message: String?) | ||
/// statucCode 500 ~ error | ||
case serverError(statusCode: Int, message: String?) | ||
/// 알 수 없는 에러 | ||
case unknown | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// | ||
// NetworkService.swift | ||
// PPACNetwork | ||
// | ||
// Created by 장혜령 on 6/8/24. | ||
// | ||
|
||
import Foundation | ||
|
||
final class NetworkService: NetworkServiceable { | ||
|
||
func request<T: Decodable>(_ request: Requestable) async -> (data: T?, error: Error?) { | ||
guard let encodedUrl = request.url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed), | ||
let url = URL(string: encodedUrl) else { | ||
return (nil, NetworkError.urlEncodingError) | ||
} | ||
|
||
let urlRequest = request.buildURLRequest(with: url) | ||
|
||
let (data, response): (Data, URLResponse) | ||
do { | ||
(data, response) = try await URLSession.shared.data(for: urlRequest) | ||
} catch { | ||
return (nil, NetworkError.invalidResponse) | ||
} | ||
|
||
guard let httpResponse = response as? HTTPURLResponse else { | ||
return (nil, NetworkError.invalidResponse) | ||
} | ||
|
||
switch httpResponse.statusCode { | ||
case 200..<300: | ||
let decoder = JSONDecoder() | ||
let decodedData = try? decoder.decode(T.self, from: data) | ||
return (decodedData, nil) | ||
case 400..<500: | ||
return (nil, NetworkError.clientError(statusCode: httpResponse.statusCode, message: String(data: data, encoding: .utf8))) | ||
case 500..<600: | ||
return (nil, NetworkError.serverError(statusCode: httpResponse.statusCode, message: String(data: data, encoding: .utf8))) | ||
default: | ||
return (nil, NetworkError.unknown) | ||
} | ||
} | ||
} |
14 changes: 0 additions & 14 deletions
14
Projects/Features/Home/Sources/Service/ExampleServiceable.swift
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
Projects/Features/Home/Sources/Service/ExempleAPIClient.swift
This file was deleted.
Oops, something went wrong.