Custom Error Messages? #1261
-
Versions:
Problem: I have used SetErrorFunction to add custom errorMessage field but it doesn't work.
Error I get in terminal:
I am stuck trying to set custom error messages for my schema. Please let me know how to do this. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
@mad-coder-365 Hi, "@fastify/type-provider-typebox": "^5.1.0", By default, the Fastify Type Provider uses Ajv under the hood, so Ajv will be responsible for generating error messages. To have TypeBox generate errors, you will need to override the Fastify validation compiler. The TypeBox provider has a Fastify compatible compiler function built in, you just need to enable it using the following. https://github.com/fastify/fastify-type-provider-typebox?tab=readme-ov-file#type-compiler I think if you set this up, the, validation errors will flow through Let me know if this helps |
Beta Was this translation helpful? Give feedback.
@mad-coder-365 Hi,
By default, the Fastify Type Provider uses Ajv under the hood, so Ajv will be responsible for generating error messages. To have TypeBox generate errors, you will need to override the Fastify validation compiler. The TypeBox provider has a Fastify compatible compiler function built in, you just need to enable it using the following.
https://github.com/fastify/fastify-type-provider-typebox?tab=readme-ov-file#type-compiler
I think if you set this up, the, validation errors will flow through
SetErrorFunction
.Let me know if this helps
S