cancel
Showing results for 
Search instead for 
Did you mean: 

SAP CPI - How to get detailed RFC error text

SFY50013
Explorer
2,186

Hello Experts,

when calling a function module using the RFC adapter in CPI with an incorrect date format, we are getting an exception but we could not catch its detailed message. The error is visible in the MPL :

"com.sap.it.rt.adapter.rfc.exceptions.RFCLibraryException: Error in executing RFC Function, cause: com.sap.conn.jco.ConversionException: (122) JCO_ERROR_CONVERSION: Cannot convert the value '14-11-2019' from type java.lang.String to type DATE at field STARTDATE"

We know that the date format is incorrect and should be YYYY-MM-DD (which is working fine) but is there a runtime property or header to catch the detailed message ?

Property ${exception.message} returns hte following message which is not helpful

com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'E' (code 69) in prolog; expected '<' at [row,col {unknown-source}]: [1,1]


Thanks for your inputs

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos
import com.sap.gateway.ip.core.customdev.util.Message;
def Message processData(Messagemessage){//get a map of properties
                def map =message.getProperties();//get an exception java classinstance
                def ex = map.get("CamelExceptionCaught");

if(ex!=null){
message.setBody(ex.getCause())

}


Answers (1)

Answers (1)

Sriprasadsbhat
Active Contributor
0 Kudos

Hello soufiane,

Please try below then you should get everything from error.

 ${exception.stacktrace}<br>


Also try using below groovy script inside your exception subprocess to manually catch the exception to get error response.

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) {
                                
                                if (ex.getClass().getCanonicalName().equals("com.sap.it.rt.adapter.rfc.exceptions.RFCLibraryException")) {
                                                
                                                // save the rfc error response as a message attachment 
                                                def messageLog = messageLogFactory.getMessageLog(message);
                                                messageLog.addAttachmentAsString("http.ResponseBody", ex.getResponseBody(), "text/plain");


                                                // copy the rfc error response to an exchange property
                                                message.setProperty("RFCErrorResp",ex.getResponseBody());


                                                // copy the rfc error response to the message body
                                                message.setBody(ex.getResponseBody());                                               
                                                
                                }
                }


                return message;
}


Regards,

Sriprasad Shivaram Bhat,

SFY50013
Explorer
0 Kudos

Hello Sri,

thank you for your help. The script gives an error :

java.lang.NoSuchMethodException: No signature of method: com.sap.it.rt.adapter.rfc.exceptions.RFCLibraryException.getResponseBody() is applicable for argument types: () values: []

I think that handling RFC exceptions is different from HTTP.