displaying field level validation errors from the backend

Hi, My backend returns validation structured validation errors on post or put, with field level error information for example:
{
"modelState": {
"name": "validate error"
},
"message": "Name: validate error"
}
{
"modelState": {
"name": "validate error"
},
"message": "Name: validate error"
}
How can I get the error for the name field to display next to the name field in refine. Is there a specific exception error structure I need to use?
21 Replies
metropolitan-bronze
metropolitan-bronze2y ago
extended-salmon
extended-salmon2y ago
Thanks for getting back to me, I've read the article and I can't find in it what I want looking for. I was hoping for a structure of an exception I as a dataProvider can throw in the create or update that'll be handled by refine to display the error correctly next to the field.
metropolitan-bronze
metropolitan-bronze2y ago
@noam.honig Im so sorry. I sent you wrong link 😦 https://refine.dev/docs/api-reference/core/providers/data-provider/#error-format this is the correct one
extended-salmon
extended-salmon2y ago
Thanks for that. In that error, how do I specify the exact error text I want to display next to each field? Something like:
{
message:"something is wrong",
statusCode:500,
errors:{
name:"Too Short",
age:"Too Young"
}
}
{
message:"something is wrong",
statusCode:500,
errors:{
name:"Too Short",
age:"Too Young"
}
}
metropolitan-bronze
metropolitan-bronze2y ago
Which form library u are using ?
extended-salmon
extended-salmon2y ago
I'm using the default one used in the tutorial
metropolitan-bronze
metropolitan-bronze2y ago
which tutorial ?
metropolitan-bronze
metropolitan-bronze2y ago
you can write custom form validation and error message like this https://refine.dev/docs/advanced-tutorials/forms/custom-form-validation/
extended-salmon
extended-salmon2y ago
I see - I was hoping for something built in refine that standardizes that as well
metropolitan-bronze
metropolitan-bronze2y ago
🙏 we will release refine 4 in 1 or 2 month. we will definitely consider this Hi @noam.honig, We discussed in the core team. We think your point is really valuable. Thank you 🙏 Do you wanna open feature request on Github ? If you open, we try to speed things up.
extended-salmon
extended-salmon2y ago
Sounds good
Omer
Omer2y ago
Remult looks great, congrats 🙂 Are you creating a dataprovider?
extended-salmon
extended-salmon2y ago
Hi @Omer, yes I'm creating a data provider, it seems fairly simple and powerful @Omer Since you mentioned remult, I would like to ask a follow-up question if that's ok. In remult I have a lot of metadata around the entities (field types, captions, validations etc...) This opens up the opportunity to create a powerful inferer that'll be based on entity metadata rather than JSON results. Is there a simple api for me to use to provide metadata to the refine inferer or do I need to create multiple inferers of my own?
Omer
Omer2y ago
@aliemirs can you help?