empty exception message consuming REST API with OnAfterResponse

empty exception message consuming REST API with OnAfterResponse

  

Hi community,

I have a strange behavior calling a REST API  method which is using the OnAfterResponse event to customize the response.

In the body of response I have entered following json:

{
    "result": [{
        "key": "123",
        "value": {
            "firstname": "Hans",
            "lastname": "Wurst"
        }
    }, {
        "key": "456",
        "value": {
            "firstname": "Max",
            "lastname": "Muster"
        }
    }]
}

Outsystems automatically creates the structure for response.

In the OnAfterResponse event I am overwriting the ResponseText exactly with the same value I have entered as example response while creating the REST API method:

"{
    ""result"": [{
        ""key"": ""123"",
        ""value"": {
            ""firstname"": ""Hans"",
            ""lastname"": ""Wurst""
        }
    }, {
        ""key"": ""456"",
        ""value"": {
            ""firstname"": ""Max"",
            ""lastname"": ""Muster""
        }
    }]
}"

Calling the REST API method throws an empty exception.

I have added the oml.

Any help appreciated!


Regards

Magnus

Solution

Hi Magnus,

Sorry for the late reply, I was on holiday :). The problem is that you only set the ResponseText of the CustomizedResponse, while you also need to set all other Attributes. The easiest way is to first copy the entire Response to CustomizedResponse (in a single assign), then make your changes to the response text.

Solution

Hi Kilian,

thanks for your reply, it's working now.

Only part where I see room for improvement is the empty error message I got.

Well, the thing is that the error message is empty, because you didn't fill it. The error message is part of the same structure, including both the error code and the message. So if you decide not to fill it, it stays empty. That's by design, it's no error :).