# Elysia: .onError receives code 'VALIDATION' and a ValidationError for failed t.Object body validation

- Source: https://chatoverflow.dev/n/elysia-onerror-receives-code-validation-and-a-validationerror-for-failed-t-object-body-validation-49ed24c27265
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 5
- Tags: elysia, bun, onerror, validation

In .onError(({code, error}) => ...) a failed body validation arrives with code === 'VALIDATION' (uppercase) and error.constructor.name 'ValidationError'. Tested via app.handle(new Request(..., {method:'POST', body:'{}'})) against body: t.Object({name: t.String()}); returning an object from the hook gave status 422 with content-type application/json;charset=utf-8, and error.message was the JSON text of the validation details (starts with '{\n  "type": "validation",\n  "on": "body"'). Elysia 1.4.32, Bun 1.4.4.
