implement bookmark tagging
This commit is contained in:
@@ -18,13 +18,16 @@ class BadRequestError extends Error {
|
||||
}
|
||||
class InternalError extends Error {}
|
||||
class UnauthenticatedError extends Error {}
|
||||
class NotFoundError extends Error {}
|
||||
|
||||
interface ErrorBody {
|
||||
code: string
|
||||
message?: string
|
||||
}
|
||||
|
||||
type QueryKey = ["bookmarks", ...ReadonlyArray<unknown>] | ["bookmarks", string, ...ReadonlyArray<unknown>]
|
||||
type QueryKey =
|
||||
| ["bookmarks" | "tags", ...ReadonlyArray<unknown>]
|
||||
| ["bookmarks" | "tags", string, ...ReadonlyArray<unknown>]
|
||||
|
||||
async function fetchApi(route: string, init?: RequestInit): Promise<Response> {
|
||||
const response = await fetch(`${import.meta.env.VITE_API_URL}/api${route}`, {
|
||||
@@ -42,6 +45,8 @@ async function fetchApi(route: string, init?: RequestInit): Promise<Response> {
|
||||
case 401: {
|
||||
throw new UnauthenticatedError()
|
||||
}
|
||||
case 404:
|
||||
throw new NotFoundError()
|
||||
default:
|
||||
throw new InternalError()
|
||||
}
|
||||
@@ -50,8 +55,8 @@ async function fetchApi(route: string, init?: RequestInit): Promise<Response> {
|
||||
function useAuthenticatedQuery<TData>(queryKey: QueryKey, fn: () => Promise<TData>) {
|
||||
const query = useQuery({
|
||||
queryKey,
|
||||
queryFn: () => fn(),
|
||||
retry: (_, error) => !(error instanceof UnauthenticatedError),
|
||||
queryFn: fn,
|
||||
retry: false,
|
||||
})
|
||||
|
||||
const navigate = useNavigate()
|
||||
@@ -76,6 +81,7 @@ export {
|
||||
BadRequestError,
|
||||
InternalError,
|
||||
UnauthenticatedError,
|
||||
NotFoundError,
|
||||
fetchApi,
|
||||
useAuthenticatedQuery,
|
||||
mutationOptions,
|
||||
|
Reference in New Issue
Block a user