MCPcopy Create free account
hub / github.com/boringstack-xyz/boringstack / applyServerErrors

Function applyServerErrors

apps/ui/src/features/auth/Auth.utils.ts:5–29  ·  view source on GitHub ↗
(
  error: unknown,
  setError: UseFormSetError<TForm>,
  fields: readonly Path<TForm>[]
)

Source from the content-addressed store, hash-verified

3import { ApiError } from "@/lib/api/ApiError";
4
5export function applyServerErrors<TForm extends FieldValues>(
6 error: unknown,
7 setError: UseFormSetError<TForm>,
8 fields: readonly Path<TForm>[]
9): boolean {
10 if (!(error instanceof ApiError) || !error.fieldErrors) {
11 return false;
12 }
13
14 for (const [field, message] of Object.entries(error.fieldErrors)) {
15 /*
16 * Match the server key against the form's own path list. `find` yields a
17 * real `Path<TForm>` element (or nothing), so setError stays type-sound
18 * with no assertion — Path<TForm> has no runtime witness to cast to.
19 * Server keys that aren't form fields are ignored.
20 */
21 const path = fields.find((candidate) => candidate === field);
22
23 if (path !== undefined) {
24 setError(path, { type: "server", message });
25 }
26 }
27
28 return true;
29}

Callers 7

Auth.utils.test.tsFile · 0.90
useLoginPageFunction · 0.90
useForgotPasswordPageFunction · 0.90
useSignUpPageFunction · 0.90
useResetPasswordPageFunction · 0.90
useSettingsPageFunction · 0.90
useProfilePageFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected