mirror of
https://github.com/umami-software/umami.git
synced 2026-02-04 04:37:11 +01:00
Updated api fetch to return an object.
This commit is contained in:
parent
e64b35f701
commit
e5cd162b83
10 changed files with 28 additions and 28 deletions
12
lib/web.js
12
lib/web.js
|
|
@ -1,6 +1,6 @@
|
|||
import { getQueryString } from './url';
|
||||
|
||||
export const apiRequest = (method, url, body) =>
|
||||
export const apiRequest = (method, url, body, headers) =>
|
||||
fetch(url, {
|
||||
method,
|
||||
cache: 'no-cache',
|
||||
|
|
@ -8,18 +8,16 @@ export const apiRequest = (method, url, body) =>
|
|||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
...headers,
|
||||
},
|
||||
body,
|
||||
}).then(res => {
|
||||
console.log({ res });
|
||||
if (res.ok) {
|
||||
return res.json();
|
||||
return res.json().then(data => ({ ok: res.ok, status: res.status, data }));
|
||||
}
|
||||
|
||||
if (['post', 'put', 'delete'].includes(method)) {
|
||||
return res.text();
|
||||
}
|
||||
|
||||
return null;
|
||||
return res.text().then(data => ({ ok: res.ok, status: res.status, res: res, data }));
|
||||
});
|
||||
|
||||
export const get = (url, params) => apiRequest('get', `${url}${getQueryString(params)}`);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue