This commit is contained in:
subodh committed 2026-03-13 10:55:15 +05:30
1 parent 6f0ebad75e
commit 789c8cebf4
1 file changed
+9
+9
View File
@@ -72,6 +72,7 @@ export default function Home() {
xhr.onload = () => { xhr.onload = () => {
if (xhr.status >= 200 && xhr.status < 300) { if (xhr.status >= 200 && xhr.status < 300) {
try {
const data = JSON.parse(xhr.responseText) as { url: string }; const data = JSON.parse(xhr.responseText) as { url: string };
const raw = data.url ?? ""; const raw = data.url ?? "";
const absolute = raw.startsWith("http") const absolute = raw.startsWith("http")
@@ -80,6 +81,10 @@ export default function Home() {
setResultUrl(absolute); setResultUrl(absolute);
setProgress(100); setProgress(100);
setStatus("done"); setStatus("done");
} catch {
setErrorMessage("Unexpected response from server.");
setStatus(preUploadStatus.current);
}
} else { } else {
let detail = "Upload failed."; let detail = "Upload failed.";
try { try {
@@ -98,6 +103,10 @@ export default function Home() {
setStatus(preUploadStatus.current); 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.open("POST", "/api/upload");
xhr.send(formData); xhr.send(formData);
}, },