Skip to Content

Error Handling in SCP-Integration Services

Hi Guys,

I'm trying to figure out a way on how to throw HTTP 500 response and set some custom error description in the response header incase of an error during validation or message failure. Eventually, I would also like to put all error details in the response body.

In the above exception subflow which begins with "Error Start" event and ends with "End Message" Event, I have the written the following script to explicitly set the status of the code to 500 and some custom header text.

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
   	def body = message.getBody();
    def map  = message.getProperties();
    def ex   = map.get("CamelExceptionCaught");
    if (ex!=null) {
		message.setBody('Test Body from CamelException');
		message.setHeader("STATUS_CODE", 500);
		message.setHeader("STATUS_TEXT", "TEST Header Validation failed from CamelException");
    }
   else{
		message.setBody('test123');	
    	message.setHeader("STATUS_CODE", 500);
   }
	return message;
}

Content modifier body

<faultMessage>
<success>false</success>
<error>
<message>${exception.message}</message>
<body>${in.body}</body>
</error>
</faultMessage>

Response:

Issue: The response status still stays 200 although I explicitly set it to HTTP 500. body content is correct though

Also noticeably when I change the "End Message" to "Error End" event in the exception subflow. I do get the HTTP 500 response, which I wanted . However, it ignores the body and the Header text I had set via the script.

Issue: Status is set to 500 but the body is overwritten with standard exception message.


How do I set HTTP 500 and Custom Header Text and Body in case of an error ?



Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Oct 24, 2017 at 09:24 AM

    Hello Amber,

    Please set below header it will work.

    Regards,

    Sriprasad Shivaram Bhat

    Add comment
    10|10000 characters needed characters exceeded

    • Hello Amber,

      With script also it works but you need to use above header which is specific to HTTP adapter of SAP CPI.

      def Message processData(Message message) {
          def map = message.getHeaders();
          map.put("CamelHttpResponseCode",900);
          message.setBody("CustomError");
          return message;
      }

      Regards,

      Sriprasad Shivaram Bhat