Add flag to api action to fetch non-JSON data.

If {text:true} or another truthy value is passed as the
`text` option, the api action will use Response.text()
instead of Response.json().
This commit is contained in:
D. Berge
2021-05-08 00:44:05 +02:00
parent ff66c9a88d
commit 983113b6cc

View File

@@ -22,7 +22,7 @@ async function api ({state, commit, dispatch}, [resource, init = {}, cb]) {
await dispatch('setCredentials');
try {
return await res.json();
return init.text ? (await res.text()) : (await res.json());
} catch (err) {
if (err instanceof SyntaxError) {
if (Number(res.headers.get("Content-Length")) === 0) {