Use r.text() instead of r.json() for error responses in handleImageUpload

The error path was throwing at r.json() parsing — r.text() lets us log
the actual raw response before trying to parse it as JSON.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Kunthawat Greethong
2026-05-04 11:21:02 +07:00
parent 881657c59a
commit 8a6e268606

View File

@@ -1242,10 +1242,15 @@ export function renderToolbar(config: ToolbarConfig): string {
}) })
.then(function(r) { .then(function(r) {
console.log("[emdash] Upload response status:", r.status); console.log("[emdash] Upload response status:", r.status);
console.log("[emdash] Upload response headers:", r.headers.get("content-type"));
if (!r.ok) { if (!r.ok) {
return r.json().then(function(e) { return r.text().then(function(text) {
console.log("[emdash] Upload error response:", JSON.stringify(e)); console.log("[emdash] Upload error text:", text);
var msg = (e && e.error && e.error.message) ? e.error.message : ("Upload failed: " + r.status); var msg = "Upload failed: " + r.status;
try {
var e = JSON.parse(text);
if (e && e.error && e.error.message) msg = e.error.message;
} catch {}
throw new Error(msg); throw new Error(msg);
}); });
} }