2 weeks ago - last edited 2 weeks ago
Hi experts,
in a classic SAP CAP application, Node.js flavour, i have defined a service.js implementation for my service.cds , with a generic error handler:
service.js
const cds = require('@sap/cds');
module.exports = async function () {
/**
* The generic error handler
*/
this.on('error', (err, req) => {
//How to retrieve req.data?
console.log('Oh no! ' + err.message);
});
};
Let's say that I execute a POST to an entity that throws a DeserializationError. The error is being catched by the error handler but the req.data is undefined.
Is there a way in this scenario to access to the body of the request which caused the error?
In this context, using context propagation works:
cds.context.http.req.data
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Arley , thank you, this works fine for entity served as projection of the ones in the data-model.cds.
In the scenario in which I am exposing an action with a custom defined type, the cds.context.http.req.data it is still undefined. Any suggestions?
define type EventMessage {
ID : UUID;
time : DateTime;
name : String;
category : String;
status : String;
}
...
action add @(restrict: [
{
grant: ['WRITE'],
to : 'admin'
}])(
ID : EventMessage:ID,
time : EventMessage:time,
name : EventMessage:name,
category : EventMessage:category,
status : EventMessage:status
) returns String;
User | Count |
---|---|
78 | |
9 | |
8 | |
7 | |
6 | |
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.