Skip to content

Commit

Permalink
[#515] Refactor NetworkAPIProtocol
Browse files Browse the repository at this point in the history
  • Loading branch information
nkhanh44 committed Oct 5, 2023
1 parent 78dafeb commit 1f226eb
Showing 1 changed file with 10 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,15 @@ extension NetworkAPIProtocol {
configuration: RequestConfiguration,
decoder: JSONDecoder
) async throws -> T {
try await withCheckedThrowingContinuation { continuation in
session.request(
configuration.url,
method: configuration.method,
parameters: configuration.parameters,
encoding: configuration.encoding,
headers: configuration.headers,
interceptor: configuration.interceptor
)
.response { response in
switch response.result {
case let .success(data):
do {
let decodedData = try decoder.decode(T.self, from: data ?? Data())
continuation.resume(returning: decodedData)
} catch {
continuation.resume(throwing: error)
}
case let .failure(error):
continuation.resume(throwing: error)
}
}
}
try await session.request(
configuration.url,
method: configuration.method,
parameters: configuration.parameters,
encoding: configuration.encoding,
headers: configuration.headers,
interceptor: configuration.interceptor
)
.serializingDecodable(T.self)
.value
}
}

0 comments on commit 1f226eb

Please sign in to comment.