Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Sources/Utils/Services/ServerClient/AsyncHttpClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ open class AsyncHttpClient<E: Error>: BaseHttpClient {
}
}

open func performRequest(method: HTTPMethod, endpoint: String) async throws -> Data {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Давай сразу добавим сюда Хедеры 🌚

Copy link
Copy Markdown
Contributor

@timonity timonity Feb 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Предлагаю написать приватный метод, в котором будет общая логика. А публичные методы performRequest<T: Decodable>(...) -> T, performRequest<T: Decodable, P: Encodable> -> T и performRequest(...) -> Data будут использовать его внутри

let encoder = getParameterEncoder(method: method)

do {
return try await request(
endpoint: endpoint,
method: method,
parameters: nil as String?,
encoder: encoder
)
.validate(validate(request:response:data:))
.serializingData()
.value
} catch let error as AFError {
throw convertError(error) ?? AFError.explicitlyCancelled
}
}

open func validateResponse(request: URLRequest?, response: HTTPURLResponse, data: Data?) -> Result<Void, E> {
assertionFailure("Subclasses must implement this method")

Expand Down