on 07-23-2021 11:04 AM
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?
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.