cancel
Showing results for 
Search instead for 
Did you mean: 

Is There a Script Example for Exception Handling in OData V4 Receiver Adapter on Cloud Integration

eakucuk
Explorer
751

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.

View Entire Topic
RenatoMiranda
Explorer

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:

RenatoMiranda_0-1736952834049.png

 

emreanil
Explorer

Thank you for your contributions 🙂

marcelom_bovo
Participant

Hi,

Thanks, it worked for me, but I had to revert the code bellow

def odataException = ex.getCause();

to

def odataException = ex.getCause().getCause();

 

RenatoMiranda
Explorer
0 Kudos
Yes marcelom_bovo, depends on the odataException returned. But I'm glad that worked for you too.