0

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".

U. Friedrich
  • 3
  • 1
  • 3
  • Not use in a validate, just use the Promise in the submit function – Eliseo Nov 16 '17 at 14:56
  • Why use Observable.fromPromise instead of using just a Observable? :) Catch and throw the error and assign the error response to a variable that you show in template. – AT82 Nov 16 '17 at 17:33
  • The "save()" methode of the entity returns a promise, therefore I use this way. – U. Friedrich Nov 17 '17 at 06:18
  • According to Wakanda's [Validate event descript](http://livedoc.wakanda.org/Datastore/Using-Datastore-Class-Events/Refusing-an-event.300-948259.en.html). The validation error can be caught when you call save() in a try catch. Like @ AJT_82 said, you can also catch and throw the error to a variable assigned to the error response. – Xiang Liu Nov 21 '17 at 22:34
  • @U.Friedrich I'm from the Wakanda team. If I understood well, in the client side you receive a generic error 500 Internal server error, instead of 'The value is too long'. We are trying to reproduce the issue. If it is reproducible I'll create an issue at: https://github.com/Wakanda/wakanda-issues/issues – hamzahik Nov 23 '17 at 12:26

1 Answers1

1

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

enter image description here

Community
  • 1
  • 1
Yann
  • 478
  • 5
  • 10
  • This works, thanks a lot. I've always seen the default message and then I didn't go deeper into whether the error message from the server is included below. – U. Friedrich Dec 05 '17 at 09:34