Some messy stuff cleaned up in Inventory UI
This commit is contained in:
@@ -45,9 +45,6 @@ public final class APIClient: Sendable {
|
||||
req.httpMethod = method
|
||||
req.setValue(contentType, forHTTPHeaderField: "Content-Type")
|
||||
|
||||
let cookieNames = HTTPCookieStorage.shared.cookies(for: url)?.map(\.name) ?? []
|
||||
print("[APIClient] \(method) \(path) — cookies: \(cookieNames)")
|
||||
|
||||
if let body {
|
||||
do {
|
||||
req.httpBody = try JSONEncoder.api.encode(body)
|
||||
@@ -60,27 +57,20 @@ public final class APIClient: Sendable {
|
||||
do {
|
||||
(data, response) = try await session.data(for: req)
|
||||
} catch {
|
||||
print("[APIClient] Network error on \(method) \(path): \(error)")
|
||||
throw APIError.networkError(error)
|
||||
}
|
||||
|
||||
guard let http = response as? HTTPURLResponse else {
|
||||
print("[APIClient] Non-HTTP response on \(method) \(path)")
|
||||
throw APIError.networkError(URLError(.badServerResponse))
|
||||
}
|
||||
|
||||
print("[APIClient] \(method) \(path) → \(http.statusCode)")
|
||||
|
||||
if http.statusCode == 401 {
|
||||
print("[APIClient] 401 — clearing session and signalling unauthorized")
|
||||
clearSessionCookies()
|
||||
onUnauthorized?()
|
||||
throw APIError.unauthorized
|
||||
}
|
||||
|
||||
guard (200..<300).contains(http.statusCode) else {
|
||||
let body = String(data: data, encoding: .utf8) ?? "<binary \(data.count)b>"
|
||||
print("[APIClient] HTTP \(http.statusCode) on \(method) \(path): \(body)")
|
||||
throw APIError.httpError(statusCode: http.statusCode, data: data)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user