From 479d201da9ed3fa73bfb68a383c52c242499e15b Mon Sep 17 00:00:00 2001 From: Admin Date: Tue, 10 Mar 2026 21:10:07 +0500 Subject: [PATCH] =?UTF-8?q?fix(ios):=20fix=20comment=20delete=20=E2=80=94?= =?UTF-8?q?=20use=20fetchVoid=20for=20204=20No=20Content=20response?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ios/LibNovel/LibNovel/Networking/APIClient.swift | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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") } }