useApi should return an actual Error.
Some checks are pending
Node.js CI / build (postgresql, 18.18) (push) Waiting to run

This commit is contained in:
Mike Cao 2025-09-14 23:57:15 -07:00
parent fc01ee9f56
commit 460200dfef
2 changed files with 5 additions and 3 deletions

View file

@ -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",

View file

@ -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);
}