PI REST-Adapter – Error-handling
with modern REST API we are facing the situation to handle different error types that we have to translate in a format the user can understand, espacially if we have a synchronous scenario.
In this example, we would like to perform a GET call to a REST API and catch all errors different to HTTP code 200 (which means OK). This is very generic error handling, but should be used as an easy example to understand the mechanism.
I create different message types for request and response. Here you can see the response message type:
As response structure, we create additionally to the normal fields an optional error structure. This structure will only be filled by REST adapter, if HTTP response is unequal 200.
Then I create a 1:1 message mapping for the“ request“ and the „response“.
But there is a special feature in the „response“ mapping. I created a UDF:
The UDF is used to generate an error message if an error occurs. So the message will visible as error in PIMON and the message is canceled. This UDF does not necessarily have to be used. It only serves as a feature.
The Argument „var1“ is only used as input for the UDF and will not be used.
The mapping for the field „errors“ looks like this:
Because I want to have a more informative error message in the PImon I configured an error handling in the REST adapter.
The expression „http_result“ is only entered in error handling.
There are the following additional expressions, which can be entered here:
from website: https://help.sap.com/erp2005_ehp_08/helpdata/en/3a/0796b585c645bdb470983a4c46e31d/frameset.htm
Before the error-handling was inserted, the following error message appear in PIMON:
After configuration of the error-handling I get the following error message in PImon:
This error message is more meaningful than if I did not enter the error handling.
You could also add a receiver determination to check if the error structure exists and add an additional receiver e.g. to send an error alert via E-mail.
I hope this blog is helpul to understand.