cancel
Showing results for 
Search instead for 
Did you mean: 

Rest Receiver Adapter - How to get error details from JSON payload in latest SP?

Former Member
0 Kudos

Hi,

I have PO 7.4 installed with the latest SP.

I am calling a synchronous REST service from SAP (RFC to REST interface) , and in case of an error, I get for instance a 409 HTTP error code, and there is payload where I can get the error message in one of the fields. I want to fetch this error message and pass it into my mapping.

If I don't configure anything in Error Handling tab - the whole message is going to fail in PO: Not good for me.

If I configure any special handling, such as Custom Result, I can pass a fixed payload into my mapping. How can I put something from the error JSON payload into this custom message?

Thanks

Yoni

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

I researched a little about REST best practices and it seems as though the correct way to send applicative error in REST is using 4XX HTTP error code.

If this is the case then the PI REST adapter has to support showing data from the payload that comes with the error. How else is the user going to guess what happened.

As an example I am attaching an error response I get from an e-commerce service. Its clear in this case that without access to the payload I cannot supply any meaningful information to the caller of the service.

This looks to me like a serious flaw in the adapter. Any ideas here? Will SAP fix that in the future? Any ways around this?

Thanks

Yoni

HTTP/1.1 409 Conflict

Cache-Control: no-cache

Pragma: no-cache

Transfer-Encoding: chunked

Content-Type: application/json; charset=utf-8

Expires: -1

x-vol-has-error: 1

x-vol-correlation: de10a6cabb7245c6a8ba377e200d9c33

x-vol-mrp: RP02

Date: Mon, 18 Apr 2016 10:40:01 GMT

{"category":"mozu","applicationName":"CommerceWebApi","errorCode":"VALIDATION_CONFLICT","message":"Validation Error: The product with code: S4013C2 will have processed quantities that exceed the quantity of the items in the order.","additionalErrorData":[],"items":[]}



Former Member
0 Kudos

Hi Yoni,

I think currently it's not possible to use specific elements of the JSON response in case of a non 20x response, but you can use {http_result} which contains the whole json payload, so in your case it would contain:

{"category":"mozu","applicationName":"CommerceWebApi","errorCode":"VALIDATION_CONFLICT","message":"Validation Error: The product with code: S4013C2 will have processed quantities that exceed the quantity of the items in the order.","additionalErrorData":[],"items":[]}


Therefore you might configure all non 20x responses to create a custom result where you fill {http_result} in a specific (optional) errorMessage field. If required you could then parse/rework the JSON string from this field in the response message mapping in order to built a more readable result.

Former Member
0 Kudos

Thank you very much!

Just the answer I was looking for.

I will test and let you know.

Former Member
0 Kudos

Works perfect!

Thanks!

Former Member
0 Kudos

Glad I could help. 🙂

orlanmartinezdu
Explorer
0 Kudos

Hello, could you kindly share the config you did? Because, i am not getting an response payload even though I've already activated the custom result handler. Appreciate your inputs. Thank you!

Answers (1)

Answers (1)

former_member182412
Active Contributor
0 Kudos

Hi Yoni,

I think this is not supported but you can try sending the http_status and http_status_text as shown in this blog section Reply with custom message in case of any error

Regards,

Praveen.

Former Member
0 Kudos

Hi,

This is not good enough as the data supplied in the JSON is much more comprehensive.

Any plans on SAP side to support that?

I am trying to think of a way around this: Is there some way that I can change the HTTP error code to 200 in an adapter module? Any other ideas?

Thanks

Yoni