mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 11:57:08 +00:00
Replace text parameter by format in Vuex API call.
Instead of { text: true } as a Fetch option, one can
now specify { format: "text" }, as well as any of these
other options, which call the corresponding Fetch method:
* "arrayBuffer",
* "blob",
* "formData",
* "json",
* "text"
This commit is contained in:
@@ -29,8 +29,16 @@ async function api ({state, getters, commit, dispatch}, [resource, init = {}, cb
|
|||||||
|
|
||||||
await dispatch('setCredentials');
|
await dispatch('setCredentials');
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return init.text ? (await res.text()) : (await res.json());
|
if (!res.bodyUsed) { // It may have been consumed by a callback
|
||||||
|
const validFormats = [ "arrayBuffer", "blob", "formData", "json", "text" ];
|
||||||
|
if (init.format && validFormats.includes(init.format)) {
|
||||||
|
return await res[init.format]();
|
||||||
|
} else {
|
||||||
|
return await res.json();
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof SyntaxError) {
|
if (err instanceof SyntaxError) {
|
||||||
if (Number(res.headers.get("Content-Length")) === 0) {
|
if (Number(res.headers.get("Content-Length")) === 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user