MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / getValidationDetailMessage

Function getValidationDetailMessage

src/utils/api-error-message.ts:34–50  ·  view source on GitHub ↗

* Join the `msg` fields of a FastAPI/Pydantic validation `detail` array * (`[{ loc, msg, type }, ...]`), or return null when there are none. With * several errors each message is prefixed with its field so they can be * told apart.

(detail: unknown)

Source from the content-addressed store, hash-verified

32 * told apart.
33 */
34function getValidationDetailMessage(detail: unknown): string | null {
35 if (!Array.isArray(detail)) return null;
36 const entries = detail
37 .filter(
38 (item): item is { loc?: unknown; msg: string } =>
39 !!item &&
40 typeof item === "object" &&
41 typeof (item as { msg?: unknown }).msg === "string" &&
42 (item as { msg: string }).msg !== "",
43 )
44 .map(({ loc, msg }) => ({ field: getValidationField(loc), msg }));
45 if (entries.length === 0) return null;
46 if (entries.length === 1) return entries[0].msg;
47 return entries
48 .map(({ field, msg }) => (field ? `${field}: ${msg}` : msg))
49 .join("; ");
50}
51
52/**
53 * Join the messages of a structured `detail.errors` array

Callers 1

getApiErrorMessageFunction · 0.85

Calls 1

getValidationFieldFunction · 0.85

Tested by

no test coverage detected