Skip to Content
0
Aug 21, 2023 at 04:06 PM

CAP how to throw meaningful error in Action handler?

224 Views Last edit Aug 21, 2023 at 04:08 PM 3 rev

Hi colleagues and David Kunz especially.

Could you please give an advice of how to throw meaningful errors in CAP actions (Bound one in my case)?

The issue is that an action handler doesn't have a regular req parameter.

The best option I found by now is

async cancelFullPO(entity, key) { 
cds.context.http.res.sendStatus(400);
cds.context.http.res.send('My Error');
}

due to the input parameters of an action

but what I want is to to operate req.error as I usually do in an ordinary handler so that I can

1) specify a target like it's described here
https://cap.cloud.sap/docs/node.js/events#using-an-object-as-argument

2) throw multiple errors at once

Thank you. Best regards.