2024 Aug 01 5:02 PM - edited 2024 Aug 01 5:09 PM
The SAP documentation provides script examples for the OData V2 Receiver Adapter and the HTTP Receiver Adapter. Using these scripts, we are able to read the error body, which is added as an attachment named ODataV2_Adapter_Response_Body
I am currently using the OData V4 Adapter for the Purchase Order API. I attempted to write a similar script to the one used for the OData V2 adapter, but it did not work.
Is there a way to get the error body for the OData V4 adapter in Cloud Integration?
Reference to SAP Documentation: Handle Exceptions
Thank you for your assistance.
Request clarification before answering.
Finaly, I created this groovy that gets the response body Json.
import groovy.json.*;
import com.sap.gateway.ip.core.customdev.util.Message;
def Message processData(Message message) {
// get a map of properties
def map = message.getProperties();
// get an exception java class instance
def ex = map.get("CamelExceptionCaught");
if (ex != null) {
def odataException = ex.getCause();
if (odataException.getClass().getCanonicalName().equals("com.sap.gw.core.ip.exception.ODataResponseParsingException") ||
odataException.getClass().getCanonicalName().equals("com.sap.gateway.core.ip.component.exception.ODataProcessingException")) {
if (odataException.getCause().getClass().getCanonicalName().equals("org.apache.olingo.client.api.communication.ODataClientErrorException")) {
// Convert payload to JSON
def jsonBuilder = new JsonBuilder(odataException.getCause().getODataError());
message.setBody(jsonBuilder.toPrettyString());
message.setHeader("CamelHttpResponseCode", "200");
}
}
}
return message;
}
This is the return:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for your contributions 🙂
Hi,
Thanks, it worked for me, but I had to revert the code bellow
def odataException = ex.getCause();
to
def odataException = ex.getCause().getCause();
User | Count |
---|---|
95 | |
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.