diff --git a/webclient/src/Submit.js b/webclient/src/Submit.js index bf2f486..21f1813 100644 --- a/webclient/src/Submit.js +++ b/webclient/src/Submit.js @@ -17,7 +17,18 @@ function Submit() { data.append('url', url); 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( ({ ok, data }) => { if (ok) {