felte icon indicating copy to clipboard operation
felte copied to clipboard

How how handle server submit errors that don't follow the validation schema?

Open RahulBadenkal opened this issue 2 years ago • 3 comments

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?

RahulBadenkal avatar Oct 10 '22 03:10 RahulBadenkal

Also had this issue

loks0n avatar Dec 28 '22 00:12 loks0n

DId you figure this out? Its not documented....

dlamon1 avatar Jan 08 '23 02:01 dlamon1

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.

sccunningham7 avatar Jan 09 '23 01:01 sccunningham7