From 4e93eb58783d9d83791a5ee90ea450d84790e5fd Mon Sep 17 00:00:00 2001 From: Oliver Bryan <04oliverbryan@gmail.com> Date: Tue, 13 Jan 2026 15:33:38 +0000 Subject: [PATCH] parseError and much improved ServerQueryInput --- packages/frontend/src/lib/server/index.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/frontend/src/lib/server/index.ts b/packages/frontend/src/lib/server/index.ts index 46cfce6..4233dbd 100644 --- a/packages/frontend/src/lib/server/index.ts +++ b/packages/frontend/src/lib/server/index.ts @@ -1,3 +1,5 @@ +import type { ApiError } from "@issue/shared"; + export * as issue from "@/lib/server/issue"; export * as organisation from "@/lib/server/organisation"; export * as project from "@/lib/server/project"; @@ -5,7 +7,16 @@ export * as sprint from "@/lib/server/sprint"; export * as timer from "@/lib/server/timer"; export * as user from "@/lib/server/user"; -export type ServerQueryInput = { - onSuccess?: (data: any, res: Response) => void; - onError?: (error: string) => void; +export type ServerQueryInput = { + onSuccess?: (data: T, res: Response) => void; + onError?: (error: ApiError | string) => void; }; + +export function parseError(error: ApiError | string): string { + if (typeof error === "string") return error; + if (error.details) { + const messages = Object.values(error.details).flat(); + return messages.join(", "); + } + return error.error; +}