cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the error details in SAP CPI when calling via HTTPS?

11-15-2024 2:01 AM
shin861231 Participant
3040 views 2 comments Go to solution
0 Likes
SAP Managed Tags
Subscribe

Hello Experts,

 

This is what I am trying to do.

shin861231_0-1731632238725.png

I will call HTTPS from Postman, and the integration flow itself will show failure, which is my intention.

At the point when I call from Postman, the body of message only shows "An internal server error occured: The MPL ID of the failed message is : ......." and returned 500 internal server error as error code.

However, what I expect is that after calling from Postman, the body of message can show the details of error, just like what can be observed in SAP CPI. 

Plus, I hope that I can change the error code as well. Now it is 500 but is it possible to change it?

I am aware that this should be done by some groovy script. Does anyone know how to achieve this?

 

Thank you.

 

0 Likes

Accepted Solutions (1)

Accepted Solutions (1)

ShaikAzmathulla
Active Participant

Hi ,

// Retrieve the exception and MPL ID (if available)
def exceptionMessage = exception.getMessage()
def mplId = message.getHeader("MPL_ID")

// Prepare the custom error message
def errorMessage = "An internal server error occurred: MPL ID: ${mplId}, Error Message: ${exceptionMessage}"

// Set the custom error message in the response body
message.setBody(errorMessage)

// Set a custom HTTP status code (for example 400 instead of 500)
message.setHeader("HTTP_Response_Code", "400")

// Log the error (optional, for debugging)
messageLogFactory.getLogger().error("Custom Error: ${errorMessage}")

Regards, 

Answers (0)