Validation error
If you use t from elysia for validation, you can provide a custom error message based on the field that fails the validation.
import { Elysia, t } from 'elysia'
error: 'Age must be a number'
error: 'Body must be an object'
Elysia will override the default error message with the custom one you provide, see Custom validation message.
Validation detail
By default Elysia also provides a Validation detail to explain what’s wrong with the validation as follows:
"title": "Validation Error",
"detail": "must be number",
"schemaPath": "#/properties/id",
"message": "must be number"
However, when you provide a custom error message, it will completely override Validation detail
To bring back the validation detail, you can wrap your custom error message in a Validation detail function.
import { Elysia, t, validationDetail } from 'elysia'
error: validationDetail('Age must be a number')
error: validationDetail('Body must be an object')
Assignment
Provide your own validation message when the request body contains an invalid age.