LiamKhoaLe commited on
Commit
5aba739
·
1 Parent(s): a3283c1

Update statics, handle HTML exception

Browse files
Files changed (1) hide show
  1. statics/script.js +9 -1
statics/script.js CHANGED
@@ -187,7 +187,15 @@ async function handleFileUpload(targetField) {
187
  body: formData
188
  });
189
  // Append result with date as header
190
- const result = await res.json();
 
 
 
 
 
 
 
 
191
  if (res.ok && result.status === "success") {
192
  const today = new Date().toLocaleDateString("en-GB"); // dd/mm/yyyy
193
  const newEntry = `\n${today}\n${result.summary}`;
 
187
  body: formData
188
  });
189
  // Append result with date as header
190
+ let result;
191
+ const ctype = res.headers.get("content-type") || "";
192
+ if (ctype.includes("application/json")) {
193
+ result = await res.json();
194
+ } else {
195
+ // probably an HTML error page
196
+ const text = await res.text();
197
+ throw new Error(`Server error: ${res.status} – ${text.slice(0,120)}…`);
198
+ }
199
  if (res.ok && result.status === "success") {
200
  const today = new Date().toLocaleDateString("en-GB"); // dd/mm/yyyy
201
  const newEntry = `\n${today}\n${result.summary}`;