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; +}