getQuery.js 592 B

1234567891011121314151617
  1. export const getQuery =
  2. () =>
  3. (url, type = 'GET', body = {}) =>
  4. fetch(url, {
  5. method: type,
  6. headers: {
  7. 'Content-Type': 'application/json',
  8. ...(localStorage.authToken ? { Authorization: 'Bearer ' + localStorage.authToken } : {}),
  9. },
  10. body: body,
  11. })
  12. .then((res) => res.json())
  13. .then((data) => {
  14. if (data.errors) {
  15. throw new Error(JSON.stringify(data.errors));
  16. } else return Object.values(data.data);
  17. });