cancel
Showing results for 
Search instead for 
Did you mean: 

Error Handling in SCP-Integration Services

former_member192561
Participant

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 ?



Accepted Solutions (1)

Accepted Solutions (1)

Sriprasadsbhat
Active Contributor
0 Kudos

Hello Amber,

Please set below header it will work.

Regards,

Sriprasad Shivaram Bhat

former_member192561
Participant
0 Kudos

Hi Sriprasad,

Appreciate your response. Do you have any Idea why it does not work with the Script ?

Sriprasadsbhat
Active Contributor
0 Kudos

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

0 Kudos

Hi,

It doesn't work. Setting the header CamelHttpResponseCode to 900, via script or Content Modifier, will result in an HTTP 502 with an HTML web page as response body.

Answers (1)

Answers (1)

d_weinberg
Participant
0 Kudos

Hi Amber,

Did you solve the issue? I experience the exact same issue.

Regards,

Daniel