on 01-21-2023 11:07 AM
Hello together,
I followed the following approach to consume an external service:
https://cap.cloud.sap/docs/guides/using-services#execute-queries
But how can I read the HTTP Status, to see if the call was successful?
Thanks a lot and best regards,
Julian
Hi julian_vogel,
In addition to what my colleague robinjayasinghe said above, please read the following:
https://cap.cloud.sap/docs/node.js/best-practices#availability-checks
On either case (Java or NodeJS), the execution on a connection object will result in either having data or it will be empty.
In case it is empty, it would probably be caused by a service call error. In that case, errors usually have any meaningful information to really help the end-user. Therefore, it is usually irrelevant to be displayed at all.
If you really need it for debugging purposes, than you could use a simple try...catch (either on Java or NodeJS) and place your run method calls inside it. Check the following NodeJS example below:
module.exports.getBPAddress = async zlimit => {
const LOG = cds.log('getBPAddress', { level: 'warn' });
const bupa = await cds.connect.to('API_BUSINESS_PARTNER');
const { A_BusinessPartner } = bupa.entities;
try {
const result = await bupa.run(SELECT.from(A_BusinessPartner, bp => {
bp('BusinessPartner'),
bp.to_BusinessPartnerAddress(addresses => {
addresses('*')
})
}).limit(zlimit));
} catch (error) {
LOG.info("API returned error: ", error);
}
};
Best regards,
Ivan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
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.