diff --git a/ios/LibNovel/LibNovel/Networking/APIClient.swift b/ios/LibNovel/LibNovel/Networking/APIClient.swift index 072cbca..eab46e6 100644 --- a/ios/LibNovel/LibNovel/Networking/APIClient.swift +++ b/ios/LibNovel/LibNovel/Networking/APIClient.swift @@ -90,6 +90,19 @@ actor APIClient { } } + /// Like `fetch` but discards the response body — use for endpoints that return 204 No Content. + func fetchVoid(_ path: String, method: String = "GET", body: Encodable? = nil) async throws { + let req = try makeRequest(path, method: method, body: body) + let (data, response) = try await session.data(for: req) + guard let http = response as? HTTPURLResponse else { + throw APIError.invalidResponse + } + guard (200..<300).contains(http.statusCode) else { + let rawBody = String(data: data, encoding: .utf8) ?? "" + throw APIError.httpError(http.statusCode, rawBody) + } + } + // MARK: - Auth struct LoginRequest: Encodable { @@ -347,8 +360,7 @@ actor APIClient { /// Delete a comment (and its replies) by ID. Only the owner can delete. func deleteComment(commentId: String) async throws { - struct Empty: Decodable {} - let _: Empty = try await fetch("/api/comment/\(commentId)", method: "DELETE") + try await fetchVoid("/api/comment/\(commentId)", method: "DELETE") } }