Service rest mapping error response

Hi,

We have create a few services in Pega infinity 24 version. We need to handle error when parsing o deserializing json request for all the services. As the service activity is not called when mapping error occurs and the execution is handled by the service rest rule, we have created a mapping error condition in the response tab of the corresponding method to get the mapping error when occurred but we need to initialize first some data that needs to be used to build or serialize the response json via json data transform configured in the mapping error response in the service rest. To serialize the json response the service rest mapping error response in the Message data is configured as followed:

  • Map from: JSON
  • Map from key: property belongs to the data error class that contains the properties used to build the json response.
  • Mapping method: Use Json Data transformation
  • Json data transform: Data transform to serialize the json response

Summarizing, i am not able to set the values in the properties belonging to a data class error which are needed to build/serialize the json response defined by the company´s API arquitecture.

The only we are able to achieve is by configuring the service rest mapping error in the message data part with the following configuation:

  • Map from: Constant
  • Map from key: Filling it in with the json itself eg: {“apperrorcode”:“DEFAULT_400”,“locale”:“en_GB”,“message”:“The input JSON format is invalid or does not match the service contract.”,“endpoint”:“v1/claims”,“status”:400,“timestamp”:“”,“tipo”:“Bad Request”}

We would like to achieve this in a different way. I would very much appreciate some help on this if you have come accross with same issue.

Regards,

Israel

What you’re seeing is expected behavior in Pega REST services.

When the incoming JSON cannot be parsed or mapped, Pega never reaches the Service Activity because the failure occurs earlier in the request processing pipeline. The request is rejected by the Service REST rule during deserialization, so there is no clipboard page or activity where you can initialize properties for your custom error response.

The Mapping Error response supports a JSON Data Transform, but it assumes the source page (or properties) already exists. Since no service activity is executed and no error page is automatically initialized with your values, the Data Transform has nothing to serialize, resulting in the behavior you’re seeing.

Possible approaches

  1. Use a custom Error Handler Activity - Check if there is an Error Handler Activity or similar extension point for REST services(it should be there, not sure). If available, you can:

Create the error page.
Populate the required properties.
Invoke the JSON Data Transform to build the response.

This is the recoomended solution because it allows you to reuse the same error-handling logic across all services.

  1. Use a Constant response (your current approach)

Using Map From = Constant is a valid workaround when handling deserialization failures. Since no clipboard context exists, returning a static JSON payload is often the only option available through the Mapping Error configuration.

  1. Centralize error handling after successful deserialization

If the JSON is syntactically valid but fails business validation, allow the request to reach the Service Activity. Then implement a common error-handling utility (activity or data transform) to build your standardized error response. This won’t help with malformed JSON but keeps business error handling consistent.

Based on the standard Service REST processing in Pega 24.x, there is no out-of-the-box hook to populate clipboard properties before the Mapping Error response is generated. That’s why the Constant mapping works, while the JSON Data Transform approach does not.

Thanks Ajan.

I would check for suggested first approach but as far as i could see it does not look like any extension point is available in service rest where i colud customize to initialize the error page.

Need to do further investigations on this.

So far, we have implemented the mapping error response as CONSTANT and we have set the json response on the “Map frm key” field.