angularvalidationwakanda

How to send back validation error to Angular2 app


In a component of my Angular4 app I use the save method of an entity. The validate event is executed before the save process and returns an error object in case of an error. How do I get the custom error object from the validate event?

Component:

Observable.fromPromise(this.workTimeDialogParams.entity.save()).subscribe(
    res => {
        debugger;
    },
    err => {
        debugger;
    }
);

server side validate event:

model.XXX.events.validate = function(event) {
    var result = {};

    if (checkCondition === false) {
        result.error = 123,
        result.errorMessage = 'The value is to long'
    }

    return result ;
};

In the subscribe function I want to get the specific error (for example 123 "The value is to long") sent by the validate function of the server and not the general error 500 "Internal server error".


Solution

  • Here is an example how to retrieve validate error though Angular.

    enter image description here