* Join the messages of a structured `detail.errors` array * (`[{ field, message }, ...]`, as the automation draft API sends next to a * generic `detail.message`), or return null when there are none. With * several errors each message is prefixed with its field.
(detail: unknown)
| 56 | * several errors each message is prefixed with its field. |
| 57 | */ |
| 58 | function getStructuredDetailErrorsMessage(detail: unknown): string | null { |
| 59 | if (!detail || typeof detail !== "object" || Array.isArray(detail)) { |
| 60 | return null; |
| 61 | } |
| 62 | const { errors } = detail as { errors?: unknown }; |
| 63 | if (!Array.isArray(errors)) return null; |
| 64 | const entries = errors |
| 65 | .filter( |
| 66 | (item): item is { field?: unknown; message: string } => |
| 67 | !!item && |
| 68 | typeof item === "object" && |
| 69 | typeof (item as { message?: unknown }).message === "string" && |
| 70 | (item as { message: string }).message !== "", |
| 71 | ) |
| 72 | .map(({ field, message }) => ({ |
| 73 | field: typeof field === "string" && field ? field : null, |
| 74 | message, |
| 75 | })); |
| 76 | if (entries.length === 0) return null; |
| 77 | if (entries.length === 1) return entries[0].message; |
| 78 | return entries |
| 79 | .map(({ field, message }) => (field ? `${field}: ${message}` : message)) |
| 80 | .join("; "); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * The fixed `detail` the Agent Server sends with every 5xx (an unhandled |
no outgoing calls
no test coverage detected