cancel
Showing results for 
Search instead for 
Did you mean: 

Use event handlers to return a custom message when making a post odata v4 cap

Thiagoc789
Participant
0 Kudos

Hello experts, I need to show my user a personalized message when he makes a post request to my service which is

myService

At the moment I have this handler but when I do the test from postman it returns the same array that I sent and the post is completed

srv.on('CREATE', 'Clientes', async (req) => {
const result = await INSERT.into(req.target).entries(req.data);
if (result) {
return {
...req.data,
message: "Cliente creado exitosamente en ClientesRest"
};
} else {
return {
message: "Error al crear el cliente en ClientesRest"
};
}
});


I appreciate your help. Thank you so much

View Entire Topic
katan_patel
Participant
0 Kudos

Hi Santiago,

Have you considered trying using methods req.notify(), req.info(), req.warn() & req.error() as a way to pass messages to the client?

Events and Requests | CAPire (cloud.sap)

The messages are passed into a response header "sap-messages" as an array.

Cheers,

Katan

Thiagoc789
Participant
0 Kudos

Is working thanks