#Custom Error Message for Validation Failure
7 messages · Page 1 of 1 (latest)
Original message from @tribal coral - Moved from #general message
Help is on the way! To mark it as solved, use the /solve command. In the meantime, here are some existing threads that may help you:
Documentation:
- Fields Overview - Field Options - Validation
- I18n - Node.js
- Custom Features - Server Feature - Nodes
Community-Help:
Hey @tribal coral
Yep iirc this is possible. You're going to want to throw an error instead of returning a string I think. Like this:
if (article._status !== 'published') {
throw new ValidationError({
collection: 'posts',
id: data.id,
errors: [{ message: 'My custom error msg', path: '_status' }],
})
}
Give that a shot
Im still getting this after changing my code to this:
if (article._status !== "published") {
throw new ValidationError({
collection: collection?.slug,
id: 1,
errors: [
{ message: "Article must be published", path: "_status" },
],
});
}
This is how it looks:
{
collection: 'feeds',
id: 1,
errors: [ { message: 'Article must be published', path: '_status' } ]
}
(I've also tried)
id: data?.id,