mirror of
https://github.com/umami-software/umami.git
synced 2025-12-08 05:12:36 +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",
|
"name": "@umami/components",
|
||||||
"version": "0.122.0",
|
"version": "0.123.0",
|
||||||
"description": "Umami React components.",
|
"description": "Umami React components.",
|
||||||
"author": "Mike Cao <mike@mikecao.com>",
|
"author": "Mike Cao <mike@mikecao.com>",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|
|
||||||
|
|
@ -2,14 +2,16 @@ import { useCallback } from 'react';
|
||||||
import { useQuery, useMutation } from '@tanstack/react-query';
|
import { useQuery, useMutation } from '@tanstack/react-query';
|
||||||
import { getClientAuthToken } from '@/lib/client';
|
import { getClientAuthToken } from '@/lib/client';
|
||||||
import { SHARE_TOKEN_HEADER } from '@/lib/constants';
|
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';
|
import { useApp } from '@/store/app';
|
||||||
|
|
||||||
const selector = (state: { shareToken: { token?: string } }) => state.shareToken;
|
const selector = (state: { shareToken: { token?: string } }) => state.shareToken;
|
||||||
|
|
||||||
async function handleResponse(res: FetchResponse): Promise<any> {
|
async function handleResponse(res: FetchResponse): Promise<any> {
|
||||||
if (!res.ok) {
|
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);
|
return Promise.resolve(res.data);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue