fix(api): 🐛 add token validation and error logging for uploads

Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
This commit is contained in:
Natalie 2026-05-17 22:23:05 -07:00
parent e5437a9baa
commit 1a6facd1ef

View file

@ -169,8 +169,19 @@ final class BlobSyncManager: @unchecked Sendable {
private func uploadBlob(id: String, data: Data, contentType: String) async throws -> String {
let path = "/client/imessage/attachments/\(id)/blob"
let responseData = try await apiClient.authenticatedMultipartUpload(path) { form in
form.append(data, withName: "blob", fileName: "blob", mimeType: contentType)
// Diagnostic: token presence at upload time
let tokenPresent = ((try? apiClient.getAuthToken()) ?? nil) != nil
log.info("BlobSyncManager: uploadBlob id=\(id) bytes=\(data.count) tokenPresent=\(tokenPresent)")
let responseData: Data
do {
responseData = try await apiClient.authenticatedMultipartUpload(path) { form in
form.append(data, withName: "blob", fileName: "blob", mimeType: contentType)
}
} catch {
let ns = error as NSError
log.warning("BlobSyncManager: uploadBlob error id=\(id) domain=\(ns.domain) code=\(ns.code) desc=\(error.localizedDescription) full=\(String(describing: error))")
throw error
}
let json = JSON(responseData)