mirror of
https://github.com/xtool-org/xtool.git
synced 2026-11-16 20:41:53 +03:00
Handle 4xx too
This commit is contained in:
@@ -45,12 +45,12 @@ extension HTTPClientProtocol {
|
||||
public func makeRequest(
|
||||
_ request: HTTPRequest,
|
||||
body: Data? = nil,
|
||||
throwOnServerError: Bool = true,
|
||||
requireHTTPSuccess: Bool = true,
|
||||
onProgress: @isolated(any) (Double?) -> Void = { _ in }
|
||||
) async throws -> (response: HTTPResponse, body: Data) {
|
||||
await onProgress(0)
|
||||
let (response, responseBody) = try await send(request, body: body.map { HTTPBody($0) })
|
||||
guard !throwOnServerError || response.status.kind != .serverError else {
|
||||
guard !requireHTTPSuccess || ![.clientError, .serverError].contains(response.status.kind) else {
|
||||
let errorBody = (try? await responseBody.collect()) ?? Data()
|
||||
throw HTTPResponseError(
|
||||
method: request.method,
|
||||
|
||||
Reference in New Issue
Block a user