Rest API no values showing error

I have this API as the OML shows, that if I try to search for "test" it will return values but if try any other thing it will display an error.

How can I customize the consumed api to display no values to show instead of error 500 or any error related to that?

Hi Marco,

How does the API response looks like? Do you have sample to post here?


Regards,

Swatantra

Swatantra Kumar wrote:

Hi Marco,

How does the API response looks like? Do you have sample to post here?


Regards,

Swatantra

Sorry the OML, didn't attach before. 


Hi Marco,

Take a look at this success article by Rui Barbosa in order to learn all about handling and customizing REST errors. Approach #3 explains how to “silence” a REST error and convert it to return HTTP Status 200 instead in the OnAfterResponse event. Be aware that this is not considered a good practice and you must always introspect the error structure for errors.

There is also an example Forge component that comes with the article.

Hope this helps!

Regards,

Nordin

Nordin Ahdi wrote:

Hi Marco,

Take a look at this success article by Rui Barbosa in order to learn all about handling and customizing REST errors. Approach #3 explains how to “silence” a REST error and convert it to return HTTP Status 200 instead in the OnAfterResponse event. Be aware that this is not considered a good practice and you must always introspect the error structure for errors.

There is also an example Forge component that comes with the article.

Hope this helps!

Regards,

Nordin


But how can I do it for example if the status is 200 but the output is simply an error message saying no values to show. And the API is expecting a different output?

I would not consider that an error message since you have got a status 200 back from the API. I would consider it a success response from the API saying that it did not find whatever you were looking for. 

PS: since I am on my phone now I am unable to looking into your sample module.

Nordin Ahdi wrote:

I would not consider that an error message since you have got a status 200 back from the API. I would consider it a success response from the API saying that it did not find whatever you were looking for. 

PS: since I am on my phone now I am unable to looking into your sample module.

My problem is that I have a situation where I get a status code =200 and the exception message says:

Failed to parse response of the method 'GetSearch' of the IOhub' REST API:
Parsing 'message': Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'IOhub+RESTGetSearch_Response[]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'message', line 2, position 12.



Hi Marco,

Ok this is a deserialization error. May I ask, how did you consume the API?

I’m willing to take a look tomorrow. Meanwhile, here are some posts with similar issues that might give you a hint.

https://www.outsystems.com/forums/discussion/40058/json-deserialize-error/

https://www.outsystems.com/forums/discussion/32491/rest-api-problem-parsing-single-element-attribute-json-array-response/

Regards,

Nordin