Validation field codes
Console request 2026-11-20 §3, added 2026-11-23. Every VALIDATION_FAILED error (422 for bodies, 400 for
query strings) carries machine-readable reasons next to the human-readable messages. Clients switch on the
codes. The messages are for people and may change.
{
error: {
code: "VALIDATION_FAILED",
message: string,
details: {
fieldErrors?: { [field: string]: string[] }, // unchanged: human-readable
formErrors?: string[], // unchanged
fieldCodes: { [field: string]: string[] }, // NEW, always present: same keys and order as fieldErrors
formCodes?: string[], // NEW, present when formErrors is: same order
// …every other key a route already returned (field, reason, cause, unknown, allowed, …) is unchanged
},
requestId: string
}
}
Rules
- The change is additive. No existing key changed or moved; clients that ignore
fieldCodessee no difference. fieldCodes[f][i]is the reason forfieldErrors[f][i]. The arrays have the same length.- A field is the top-level body or query key (Zod's
path[0]). Domain checks may use a dotted name such asbatteryTemperature.enabledorperiod.from, exactly as infieldErrors. - A domain error shaped
{field, reason}(nofieldErrors) getsfieldCodes: { [field]: [reason] }whenreasonis UPPER_SNAKE, otherwiseINVALID. - Unknown query parameters on a strict route (
details.unknown) getUNKNOWN_FIELDeach. - Codes are stable: never renamed or removed once shipped. New codes may be added, so treat an unknown code
like
INVALID. - Source of truth:
VALIDATION_FIELD_CODESincse-http-bepackages/core/src/validation-codes.ts. The pipeline adds the codes inpackages/api/src/http/respond.ts.
Generic codes (schema checks)
| Code | Meaning |
|---|---|
REQUIRED | the field is missing (or required by another field's value) |
INVALID_TYPE | wrong JSON type (e.g. a number where a string is expected) |
INVALID_NUMBER | not a finite number |
INVALID_VALUE | not one of the allowed literal/union values |
INVALID_ENUM | not one of the listed enum values |
INVALID_FORMAT | string does not match the expected format (ULID, regex, …) |
INVALID_EMAIL | not an email address |
INVALID_URL | not a URL |
INVALID_DATETIME | not an ISO-8601 date/time |
INVALID_DATE | not a valid date |
NOT_MULTIPLE_OF | number is not a multiple of the step |
TOO_SHORT / TOO_LONG / INVALID_LENGTH | string length below minimum / above maximum / not the exact length |
TOO_SMALL / TOO_LARGE | number or date out of range |
TOO_FEW_ITEMS / TOO_MANY_ITEMS | array size out of range |
UNKNOWN_FIELD | the field is not accepted (strict body or query) |
BODY_NOT_ALLOWED | the route takes no body (form-level) |
INVALID | any other failure, including a custom rule with no specific code yet |
Domain codes
| Code | Field(s) today | Meaning |
|---|---|---|
INCOMPATIBLE_WITH_GRID_CONNECTION | exportRate (plant tariff) | only allowed on grid-connected plants |
REQUIRES_BATTERY | batteryTemperature.enabled (plant alert rules) | the plant has no battery |
MUST_DIFFER | notifications.quietHours.end | start and end must differ |
NOT_ACCEPTED | phone | the identity provider refused the value |
NOT_ALLOWED_FOR_ROLE | businessOrgId (plant transfer) | only Super Admin / Administrator may set it |
REQUIRES_CUSTOMER | inviteCustomer (create plant) | needs a customer |
CUSTOMER_EMAIL_MISSING | inviteCustomer | the customer has no contact email |
TEMPLATE_UNAVAILABLE | templateKey (reports) | not an available template |
REQUIRES_CUSTOMER_TEMPLATE | perCustomer (report schedules) | needs a CUSTOMER-audience template |
RECIPIENTS_WITHOUT_ACCESS | recipients (report schedules) | some recipients cannot see reports on this scope |
OUT_OF_RANGE | limit (report schedules list) | integer outside the allowed range |
PLATFORM_ORG_NOT_ALLOWED | X-Org-Id (reports) | select a Business, not the platform org |
MULTIPLE_OPERATORS | scope.ids (reports) | plants span more than one operator |
INVALID_TIMEZONE | timezone | not an IANA time zone |
RANGE_INVERTED | period.from | start after end |
IN_FUTURE | period.to | ends in the future |
RANGE_TOO_LONG | period | spans more days than allowed |
NOT_FOUND_IN_ORG | scope, recipients (notification rules) | a referenced target does not exist in the organisation |
Reasons passed through from {field, reason} errors
These routes already returned details.reason; it now also appears as the field's code:
INELIGIBLE_ASSIGNEE (work-order technician, alert installer proof), DEVICE_NOT_ON_PLANT,
CUSTOMER_NOT_LINKED, CUSTOMER_PLANT_MISMATCH, END_USER_ONLY, END_USER_SCOPE_PLANTS_ONLY, INSTALLER_SCOPE_PLANTS_ONLY,
SCOPE_RULE_FORCES_ALL, CONFIRMATION_REQUIRED, ASSET_NOT_FOUND, ASSET_NOT_READY, ASSET_SLOT_MISMATCH,
NOT_AN_IMAGE, SIZE_MISMATCH, TYPE_MISMATCH. A {field} error with no reason gets INVALID.
Illustrative example (not a captured execution)
Derived from assertTariffFitsPlant (packages/core/src/plants/settings.ts): setting an export rate on an
off-grid plant.
{
"error": {
"code": "VALIDATION_FAILED",
"message": "Request validation failed",
"details": {
"formErrors": [],
"fieldErrors": { "exportRate": ["is only allowed on grid-connected plants"] },
"fieldCodes": { "exportRate": ["INCOMPATIBLE_WITH_GRID_CONNECTION"] },
"formCodes": []
},
"requestId": "<request id>"
}
}