diff --git a/lib/www/client/source/src/store/modules/api/actions.js b/lib/www/client/source/src/store/modules/api/actions.js index 93f761d..3722737 100644 --- a/lib/www/client/source/src/store/modules/api/actions.js +++ b/lib/www/client/source/src/store/modules/api/actions.js @@ -4,7 +4,18 @@ async function api ({state, commit, dispatch}, [resource, init = {}]) { // this.loading = true; const res = await fetch(`${state.apiUrl}${resource}`, init); if (res.ok) { - return await res.json(); + try { + return await res.json(); + } catch (err) { + if (err instanceof SyntaxError) { + if (Number(res.headers.get("Content-Length")) === 0) { + // res.json() cannot parse an empty response and we + // have run into this case. We just return undefined. + return; + } + } + throw err; + } } else { await dispatch('showSnack', [res.statusText, "warning"]); }