mirror of
https://github.com/umami-software/umami.git
synced 2025-12-06 01:18:00 +01:00
useApi should return an actual Error.
Some checks are pending
Node.js CI / build (postgresql, 18.18) (push) Waiting to run
Some checks are pending
Node.js CI / build (postgresql, 18.18) (push) Waiting to run
This commit is contained in:
parent
fc01ee9f56
commit
460200dfef
2 changed files with 5 additions and 3 deletions
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@umami/components",
|
||||
"version": "0.122.0",
|
||||
"version": "0.123.0",
|
||||
"description": "Umami React components.",
|
||||
"author": "Mike Cao <mike@mikecao.com>",
|
||||
"license": "MIT",
|
||||
|
|
|
|||
|
|
@ -2,14 +2,16 @@ import { useCallback } from 'react';
|
|||
import { useQuery, useMutation } from '@tanstack/react-query';
|
||||
import { getClientAuthToken } from '@/lib/client';
|
||||
import { SHARE_TOKEN_HEADER } from '@/lib/constants';
|
||||
import { httpGet, httpPost, httpPut, httpDelete, FetchResponse, ErrorResponse } from '@/lib/fetch';
|
||||
import { httpGet, httpPost, httpPut, httpDelete, FetchResponse } from '@/lib/fetch';
|
||||
import { useApp } from '@/store/app';
|
||||
|
||||
const selector = (state: { shareToken: { token?: string } }) => state.shareToken;
|
||||
|
||||
async function handleResponse(res: FetchResponse): Promise<any> {
|
||||
if (!res.ok) {
|
||||
return Promise.reject(res.data?.error as ErrorResponse);
|
||||
const { message, code, status } = res?.data?.error || {};
|
||||
|
||||
return Promise.reject(Object.assign(new Error(message), { code, status }));
|
||||
}
|
||||
return Promise.resolve(res.data);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue