felte
felte copied to clipboard
How how handle server submit errors that don't follow the validation schema?
If the server returns a error that is not specifically tied to a form control, then how do i store the error since I can't transform the error to the form schema?
Also had this issue
DId you figure this out? Its not documented....
Just handle it outside using a variable. The error handling seems to be configured purely towards the form fields themselves. In theory you could add a fake field to the errors store and use a validation reporter for it, but I haven't tried that and feel it would get messy fast. Also likely to result in type errors if you are using TS.
My implementation (in TS):
onError: (error) => {
if (error instanceof Error) {
formError = error.message;
} else if (error instanceof HttpError) {
return error.errors;
}
},
Where formError
is a block alert above the form. error.errors
from any HttpError
object will be server side validations in the format expected by Felte.