diff --git a/frontend/src/app/page.tsx b/frontend/src/app/page.tsx index 2095753..45a21db 100644 --- a/frontend/src/app/page.tsx +++ b/frontend/src/app/page.tsx @@ -72,14 +72,19 @@ export default function Home() { xhr.onload = () => { if (xhr.status >= 200 && xhr.status < 300) { - const data = JSON.parse(xhr.responseText) as { url: string }; - const raw = data.url ?? ""; - const absolute = raw.startsWith("http") - ? raw - : `https://${raw.replace(/^\/\//, "")}`; - setResultUrl(absolute); - setProgress(100); - setStatus("done"); + try { + const data = JSON.parse(xhr.responseText) as { url: string }; + const raw = data.url ?? ""; + const absolute = raw.startsWith("http") + ? raw + : `https://${raw.replace(/^\/\//, "")}`; + setResultUrl(absolute); + setProgress(100); + setStatus("done"); + } catch { + setErrorMessage("Unexpected response from server."); + setStatus(preUploadStatus.current); + } } else { let detail = "Upload failed."; try { @@ -98,6 +103,10 @@ export default function Home() { setStatus(preUploadStatus.current); }; + // Explicitly set responseType to "text" so Firefox does not attempt to + // parse the JSON response body as XML (which would log a benign but + // confusing "XML Parsing Error" in the console). + xhr.responseType = "text"; xhr.open("POST", "/api/upload"); xhr.send(formData); },