fix: Improve error handling for non-JSON server responses in Submit

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2025-11-21 22:59:15 +00:00
parent 7523426f15
commit 7b84573dd8

View File

@@ -17,7 +17,18 @@ function Submit() {
data.append('url', url); data.append('url', url);
fetch('/api/submit', { method: 'POST', body: data }) fetch('/api/submit', { method: 'POST', body: data })
.then(res => res.json().then(data => ({ ok: res.ok, data }))) .then(res => {
if (res.ok) {
return res.json().then(data => ({ ok: true, data: data }));
}
// Handle error responses
return res.json()
.then(data => ({ ok: false, data: data })) // Our API's JSON error
.catch(() => {
// Not a JSON error from our API, so it's a server issue
throw new Error(`Server responded with ${res.status} ${res.statusText}`);
});
})
.then( .then(
({ ok, data }) => { ({ ok, data }) => {
if (ok) { if (ok) {