framework4 icon indicating copy to clipboard operation
framework4 copied to clipboard

Is there a way to change the default ErrorBuilder Object Structure?

Open LandyCuadra opened this issue 4 years ago • 2 comments

Is the feature request related to a problem? Please describe. I am trying to customize the error response by adding/changing some keys to it:

this is the default error object

{
        name: 'String: error-name-or-error-code',
        error: 'String: error description',
        path: 'String: absolute path to invalid variable',
        index: Number // optional, array index if some item in array is invalid
}

Describe the solution you'd like would to know a way to add fields, that can be invoke with $.invalid()

{
        code: 'Number: Error code',
        name: 'String: error-name-or-error-code',
        message: 'String: error description',
        show: 'Boolean: flag to show or not error message',
}

Describe alternatives you've considered I have tried using the ErrorBuilder AddTransform function, to rename the fields.... but but it is kind of messy to assign builder['show'] = Boolean(err.path)... also I am limited to the quantity of fields of the default object

LandyCuadra avatar Jan 13 '22 18:01 LandyCuadra

How do you imagine to assign .show field? From where? Where do you want to specify it?

  • $.invalid() method contains fixed arguments.You can't change them - or you may change them, but I don't recommend it
  • I recommend to working with specified fields in the ErrorBuilder

BTW: you can extend error builder instance dynamically in the schemas like this:

$.error. // --> is ErrorBuilder instance
$.error.visible = { errorid1: true, errorid2: true };

Then you can use it in transformation like this:

ErrorBuilder.addTransform('custom', function(isresponse) {
    this.visible. // your data
    for (var err of this.items)
        err.show = this.visible[err.name];
}, true);

petersirka avatar Jan 13 '22 19:01 petersirka

You suggestion was correct, I was misunderstanding the function of error builder.... Finally I solved it with $.success(false, ErrorObject)... Thank you

LandyCuadra avatar Jan 14 '22 16:01 LandyCuadra