on 2023 Aug 28 10:16 AM
Hi colleagues,
usually if multiple errors are expected we throw it like this:
srv.on('CREATE', 'myEntity' req => {
if (true) {
req.error(400, 'nope 1');
req.error(400, 'nope 2');
return;
}
})
Sometimes though we want to clean up our handler so that it turns into kind of this:
validateBeforeCreateMyEntity(req) {
if (true) {
req.error(400, 'nope 1');
req.error(400, 'nope 2');
// here I want to reject the request with multiple errors which means I probably can't use req.reject as it returns only a single error
}
}
srv.before('CREATE', 'myEntity' req => {
validateBeforeCreateMyEntity(req);
// assume we have 50 more lines here
})
Is there currently any way to do it?
p.s currently in CAP documentation it's just
if (req.errors) //> get out somehow...
Thank you.
Request clarification before answering.
HI Mikhail,
An example rejecting with multiple errors in before handler is here: https://cap.cloud.sap/docs/node.js/core-services#srv-handle-event
// before phase
await Promise.all (matching .before handlers)
if (req.errors) throw req.reject() // without args
Regards,
Vitaly
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
for history:
req.reject(); // without parameters
works like a charm.
vitaly.kozyura thanks a lot!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
11 | |
9 | |
8 | |
7 | |
5 | |
4 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.