From 43a3e692fc6c7bacec8e3a234f820eae7241ca53 Mon Sep 17 00:00:00 2001 From: ComputerTech Date: Tue, 10 Mar 2026 19:13:39 +0000 Subject: [PATCH] Fix upload error handling; log 413 nginx size limit clearly --- index.html | 1 - script.js | 56 +++++++++++++++++++++++++++++------------------------- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/index.html b/index.html index 1b2425c..ba96277 100644 --- a/index.html +++ b/index.html @@ -71,7 +71,6 @@
-
diff --git a/script.js b/script.js index 50df208..528a0cc 100644 --- a/script.js +++ b/script.js @@ -1572,44 +1572,48 @@ async function handleFileUpload(event) { progressRow.appendChild(barWrap); progressContainer.appendChild(progressRow); - try { - return new Promise((resolve, reject) => { - const xhr = new XMLHttpRequest(); - xhr.open('POST', '/upload', true); + return new Promise((resolve) => { + const xhr = new XMLHttpRequest(); + xhr.open('POST', '/upload', true); - xhr.upload.onprogress = (e) => { - if (e.lengthComputable) { - const percent = (e.loaded / e.total) * 100; - barInner.style.width = percent + '%'; - } - }; + xhr.upload.onprogress = (e) => { + if (e.lengthComputable) { + const percent = (e.loaded / e.total) * 100; + barInner.style.width = percent + '%'; + } + }; - xhr.onload = () => { - if (xhr.status === 200) { + xhr.onload = () => { + if (xhr.status === 200) { + try { const result = JSON.parse(xhr.responseText); if (result.success) { barInner.style.background = '#00ff88'; - resolve(); } else { barInner.style.background = '#ff4444'; - reject(new Error(result.error)); + nameSpan.title = result.error || 'Upload failed'; + console.error(`[UPLOAD] ${file.name}: ${result.error}`); } - } else { + } catch (e) { barInner.style.background = '#ff4444'; - reject(new Error(`HTTP ${xhr.status}`)); + console.error(`[UPLOAD] Bad response for ${file.name}`); } - }; - - xhr.onerror = () => { + } else { barInner.style.background = '#ff4444'; - reject(new Error('Network error')); - }; + nameSpan.title = `HTTP ${xhr.status}`; + console.error(`[UPLOAD] ${file.name}: HTTP ${xhr.status}${xhr.status === 413 ? ' — file too large (nginx limit)' : ''}`); + } + resolve(); // Always resolve so other uploads continue + }; - xhr.send(formData); - }); - } catch (error) { - console.error(`[ERROR] Upload error: ${error}`); - } + xhr.onerror = () => { + barInner.style.background = '#ff4444'; + console.error(`[UPLOAD] ${file.name}: Network error`); + resolve(); + }; + + xhr.send(formData); + }); }); // Run uploads in parallel (limited to 3 at a time for stability if needed, but let's try all)