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:
@@ -1242,10 +1242,15 @@ export function renderToolbar(config: ToolbarConfig): string {
|
||||
})
|
||||
.then(function(r) {
|
||||
console.log("[emdash] Upload response status:", r.status);
|
||||
console.log("[emdash] Upload response headers:", r.headers.get("content-type"));
|
||||
if (!r.ok) {
|
||||
return r.json().then(function(e) {
|
||||
console.log("[emdash] Upload error response:", JSON.stringify(e));
|
||||
var msg = (e && e.error && e.error.message) ? e.error.message : ("Upload failed: " + r.status);
|
||||
return r.text().then(function(text) {
|
||||
console.log("[emdash] Upload error text:", text);
|
||||
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);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user