Files
goclaw/ui/web/src/lib/error-utils.ts
T
viettranx eb318ad8c3 feat(ui): add toast notifications and loading spinners to all save/mutation buttons
- Add userFriendlyError() helper to hide 5xx errors from users
- Add Loader2 animate-spin to all save/update/create/delete buttons
- Add useMinLoading(600ms) to StickySaveBar for visible feedback
- Move toast notifications from components into hooks (single source)
- Remove inline saved/saveError state in favor of toast system
- Add toast to all mutation hooks: agents, channels, skills, builtin-tools,
  sessions, teams, storage, tts, cron, providers, config
- Add i18n toast keys for en/vi/zh across all namespaces
- Deduplicate toast calls in team board components
2026-03-20 15:06:57 +07:00

15 lines
552 B
TypeScript

import { ApiError, ErrorCodes } from "@/api/errors";
import i18n from "@/i18n";
/** Map API errors to user-friendly messages. Hides 5xx/INTERNAL details from users. */
export function userFriendlyError(err: unknown): string {
if (err instanceof ApiError) {
if (err.code === ErrorCodes.INTERNAL || err.code === "HTTP_ERROR" || err.code === ErrorCodes.UNAVAILABLE) {
return i18n.t("common:errors.serverError");
}
return err.message;
}
if (err instanceof Error) return err.message;
return i18n.t("common:errors.serverError");
}