cancel
Showing results for 
Search instead for 
Did you mean: 

CAP Java: only 1 error message is returned at a time from service request

former_member758380
Discoverer
0 Kudos

I have created a cds entity with multiple validations such as mandatory and range:

entity Authors : cuid {
        @mandatory firstname : String(111);
        @mandatory lastname  : String(111);
        @assert.range : [
        0,
        100
    ]   age : Integer; 
        books     : Association to many Books on books.author = $self;
    }

However, when the user submitted an invalid record, the service only return 1 error message at a time even though there suppose to be multiple errors. Sample query:

curl -X POST http://localhost:8080/odata/v4/AdminService/Authors \
-H "Content-Type: application/json" \
-d '{"ID": "286ae4b1-b845-4af8-9827-4eb04fe5f382", "firstname": "Jenn", "age": 120}'

By right this should returned 2 error messages(missing lastname, age out of range), however the backend service only return 1 error message.

The second error message only shows up when the first error is fixed, in this case when I provided the value for lastname:

Is this consider a bug in CAP Java as CAP nodejs seems like able to return all the error message at once?

Accepted Solutions (1)

Accepted Solutions (1)

marcbecker
Contributor
0 Kudos

Yes, this is currently a limitation, but it will be addressed with the upcoming 1.18.0 release of CAP Java!

EDIT: This has been meanwhile addressed. Please see our updated documentation on this topic: https://cap.cloud.sap/docs/java/indicating-errors#throwing-a-serviceexception-from-messages

You can find an example of an event handler collecting multiple error messages in our cloud-cap-samples-java application: https://github.com/SAP-samples/cloud-cap-samples-java/blob/main/srv/src/main/java/my/bookshop/handle...

marcbecker
Contributor

You can take a look at the cloud-cap-samples-java application. For example the validation of an Order supports collecting multiple error messages: https://github.com/SAP-samples/cloud-cap-samples-java/blob/main/srv/src/main/java/my/bookshop/handle...

Please also have a look at our updated documentation on this topic: https://cap.cloud.sap/docs/java/indicating-errors#throwing-a-serviceexception-from-messages

I updated my answer to reflect this new information.

Answers (0)