Changelog - 2026-06-14
Schema-Driven Validation Codes & Safer Production Errors
Security Breaking Change EnhancementIn one line. Validation errors now carry a stable, localizable messageCode, database errors map to better status codes, and production error responses no longer leak database internals or raw system error text.
What changed
- 422 responses carry a real
messageCode. Aparams.codeset in the schema wins; otherwise the raw Zod code (for exampleinvalid_type).messagebecomes that issue's text instead of the literal"ValidationError". - Database errors classify by SQLSTATE class. Classes
22,23and44return400. Classes42,53,0A,25and28still return500. - Retryable conflicts return
409.40001and40P01return409 ConflictwithmessageCode: "database.conflict", not500. - No leaks in production. A database client error exposes only the base message, never
detail,tableorconstraint. Any error without an explicitstatusCodereturns"Internal Server Error". Non-production is unchanged. rootKeyapplies to 422 responses. They are wrapped undererror.rootKeylike every other error.- No crash on a non-string error
code. For example a numeric gRPC code no longer throws in the handler.
Attach a stable code to a custom Zod check:
schema.refine(fn, {
message: 'Must not exceed 4 decimal places',
params: { code: 'numeric.decimal.too_many_places' },
});
schema.superRefine((value, ctx) =>
ctx.addIssue({ code: 'custom', message: '...', path: ['items', i, 'quantity'], params: { code: 'numeric.decimal.too_many_places' } }),
);Built-in checks (type, .min, .email, ...) cannot carry a custom code in Zod v4. Re-express them as a refine if you need one.
Who is affected
- Frontends that parse
message: "ValidationError", readdetail,tableorconstraintfrom a production database error, or depend on a500for an unlisted class-22 or class-23 Postgres code. Update them (see breaking changes). - Apps that set
error.rootKey. 422 responses are now wrapped. - Schema authors.
params.codeis optional. Existing schemas need no change. - Backend code. No source change needed.
Breaking changes
WARNING
No source migration is required, but the response body changes for some errors. Update any frontend that parsed the old shapes.
422
messageis no longer"ValidationError". MapmessageCodeto a localized string, falling back tomessage.details.cause[]is unchanged.jsonc// Before { "message": "ValidationError", "statusCode": 422, "details": { "cause": [ /* ... */ ] } } // After { "message": "<first issue's message>", "messageCode": "<params.code or raw zod code>", "statusCode": 422, "details": { "cause": [ /* ... */ ] } }rootKeynow wraps validation responses. If your app setserror.rootKey, 422 responses are wrapped as{ "<rootKey>": { /* ... */ } }. Before, the body was unwrapped.Production database error messages are generic.
messageno longer includesDetail:,Table:orConstraint:lines, and unexpected errors return"Internal Server Error". UserequestIdand server logs for diagnostics.Unlisted class-22 and class-23 codes return
400. They returned500before, and now return400with a fallback message.
Details
- Security. The database
detailfield echoes row values (for exampleKey (email)=(a@b.com) already exists) and names tables and constraints. Raw messages of unexpected errors could carry SQL, schema names, or a connection host and port. Both were visible in production before this release.details.stackanddetails.causestay non-production only. - Builds on Error Responses - messageCode & Extra Fields.
- See the Middlewares Reference.