Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
424 changes: 217 additions & 207 deletions clients/admin/package-lock.json

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions clients/admin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@
},
"engines": {
"node": ">=20"
},
"overrides": {
"esbuild": "^0.28.1"
}
}
8 changes: 2 additions & 6 deletions clients/admin/src/components/users/create-user-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
DialogBody,
DialogFooter,
} from "@/components/ui/dialog";
import { ApiRequestError } from "@/lib/api-client";
import { describeError } from "@/lib/api-client";

// ─── Schema (identical to the old create page) ───────────────────────────────

Expand Down Expand Up @@ -124,11 +124,7 @@ export function CreateUserDialog({
navigate(result.userId ? `/users/${result.userId}` : "/users");
},
onError: (err) => {
const detail =
err instanceof ApiRequestError
? err.problem?.detail ?? err.problem?.title ?? err.message
: (err as Error).message;
toast.error("Create failed", { description: detail });
toast.error("Create failed", { description: describeError(err) });
},
});

Expand Down
26 changes: 25 additions & 1 deletion clients/admin/src/lib/api-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ export type ApiError = {
status: number;
title?: string;
detail?: string;
errors?: Record<string, string[]>;
// FluentValidation errors arrive keyed by field (Record); CustomException
// (e.g. Identity registration failures) sends a flat string[]. Handle both.
errors?: Record<string, string[]> | string[];
reason?: string;
[key: string]: unknown;
};
Expand All @@ -21,6 +23,28 @@ export class ApiRequestError extends Error {
}
}

/**
* Build a user-facing message from an error. When the server includes specific
* reasons in the ProblemDetails `errors` extension (validation failures,
* Identity errors like "Email is already taken"), those are shown — they tell
* the user what to fix. Otherwise falls back to detail / title / message.
*/
export function describeError(err: unknown): string {
if (err instanceof ApiRequestError) {
const raw = err.problem?.errors;
const details = Array.isArray(raw)
? raw.filter((e): e is string => typeof e === "string")
: raw && typeof raw === "object"
? Object.values(raw)
.flat()
.filter((e): e is string => typeof e === "string")
: [];
if (details.length > 0) return details.join(" ");
return err.problem?.detail ?? err.problem?.title ?? err.message;
}
return err instanceof Error ? err.message : String(err);
}

type RequestInitEx = RequestInit & { skipAuth?: boolean; timeoutMs?: number };

const DEFAULT_TIMEOUT_MS = 30_000;
Expand Down
Loading
Loading