fix(ios): fix comment delete — use fetchVoid for 204 No Content response
Some checks failed
CI / Scraper / Lint (pull_request) Failing after 7s
CI / Scraper / Test (pull_request) Successful in 19s
CI / Scraper / Docker Push (pull_request) Has been skipped
CI / UI / Build (pull_request) Successful in 25s
CI / UI / Docker Push (pull_request) Has been skipped
iOS CI / Build (push) Has been cancelled
iOS CI / Test (push) Has been cancelled
iOS CI / Build (pull_request) Successful in 1m43s
iOS CI / Test (pull_request) Successful in 4m53s
Some checks failed
CI / Scraper / Lint (pull_request) Failing after 7s
CI / Scraper / Test (pull_request) Successful in 19s
CI / Scraper / Docker Push (pull_request) Has been skipped
CI / UI / Build (pull_request) Successful in 25s
CI / UI / Docker Push (pull_request) Has been skipped
iOS CI / Build (push) Has been cancelled
iOS CI / Test (push) Has been cancelled
iOS CI / Build (pull_request) Successful in 1m43s
iOS CI / Test (pull_request) Successful in 4m53s
This commit is contained in:
@@ -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) ?? "<non-utf8 data, \(data.count) bytes>"
|
||||||
|
throw APIError.httpError(http.statusCode, rawBody)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - Auth
|
// MARK: - Auth
|
||||||
|
|
||||||
struct LoginRequest: Encodable {
|
struct LoginRequest: Encodable {
|
||||||
@@ -347,8 +360,7 @@ actor APIClient {
|
|||||||
|
|
||||||
/// Delete a comment (and its replies) by ID. Only the owner can delete.
|
/// Delete a comment (and its replies) by ID. Only the owner can delete.
|
||||||
func deleteComment(commentId: String) async throws {
|
func deleteComment(commentId: String) async throws {
|
||||||
struct Empty: Decodable {}
|
try await fetchVoid("/api/comment/\(commentId)", method: "DELETE")
|
||||||
let _: Empty = try await fetch("/api/comment/\(commentId)", method: "DELETE")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user