essential/validation #604
Replies: 4 comments 6 replies
-
|
Can I use Zod for validation, since that's what the project is using Clent side already, or must I use t from Elysia? |
Beta Was this translation helpful? Give feedback.
-
|
How can I have a response validator for 200 but keep the default for the other error codes? {
headers: headersValidator,
query: searchValidator,
response: {
200: getAllResponseValidator,
},
beforeHandle({ headers, status }) {
const apiKey = headers['x-api-key'];
if (!apiKey) {
return status(401);
}
const payload = jwtSigner.decode(apiKey);
if (payload.role !== 'admin') {
return status(403);
}
},
}For example, this wont work because, 401 and 403 just blow up errors. |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
|
Is there a way to fully customize the validation errors that are returned to the client in a typesafe way? I see how one can define custom error messages, but according to eden treaty a validation error always created a 422 status response with these fields: { what if i wanted to change the status code to something else? Or if I wanted to add an extra property on here? How could I do it in such a way that the eden treaty also knows about it? |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
essential/validation
Schemas are strictly typed definitions, used to infer TypeScript's type and data validation of an incoming request and outgoing response. Elysia's schema validation is based on Sinclair's TypeBox, a TypeScript library for data validation.
https://elysiajs.com/essential/validation
Beta Was this translation helpful? Give feedback.
All reactions