48
Views
8
Comments
Solved
What define the verbose of an error message?
Application Type
Traditional Web, Mobile, Reactive, Service

Hi there,

when i consume 3rd party API, i am wondering:

1. the message too short in the action call:

2. the message too technically in Service Center:

3, but the winner one is like this in the Test Tab because it explained more clearly. For example: Bad request 400 is too many causes- wrong parameter, somekind  like below, etc -. In my case if not using test, it will be very hard to know where did i go wrong: 

Is it settable?

thanks and regards

 

2024-05-02 09-49-04
Murali Manoharan V
Champion
Solution

No outsystems have a default functionality if the request is not success(200, 201,etc), It gives http status code as 400 bad request as error message by default. 


If you hit same api in postman it will give detailed error message. To capture that error message go to on after response and use exception handler to get that detailed error response "CustomizedResponse.ResponseText"


I achieved your need like this already

Regards

Murali

2019-09-30 07-35-56
Aurelio Junior
Solution

Hello,

OutSystems automatically throws an exception whenever a REST API returns a status code in the 400 range, which prevents you from getting the error details in the API method's response. You can work around this though. First of all, make sure you have an error output parameter in your consumed REST method. You can use the "Test" tab to automatically generate this by intentionally making a request that results in an error and then copying the response to the body:

Then, you can use the API's "OnAfterResponse" callback to manually override the status code, preventing the platform from automatically throwing an exception. Something like this:

Be advised that this will mask all 400 errors returned by your consumed API, so you have to make sure to always check the method's response for errors after calling it.

2025-01-09 14-56-57
IQ78

Hi, thanks

So, after it is OK, we capture the error inside a local variable?

regards

2019-09-30 07-35-56
Aurelio Junior

Yes, you can look into the API method's response to get the error message. Something like this:


2024-05-02 09-49-04
Murali Manoharan V
Champion

Yes @ibox 

You can achieve this

In on after response of API you can code like this to avoid http status code errors

Condition for if is "Index(IntegerToText(CustomizedResponse.StatusCode),"2") = 0", because http status code status with 2 is always success, rather than that 400, 401 or whatever it may be it will raise exception. In that exception message you can assign "CustomizedResponse.ResponseText"

it contains your expected error message from api


Regards

Murali

2025-01-09 14-56-57
IQ78

hi,

I use the default one, all return 400 Bad Request, so there is no variants like 401, 402, etc.

regards


2024-05-02 09-49-04
Murali Manoharan V
Champion
Solution

No outsystems have a default functionality if the request is not success(200, 201,etc), It gives http status code as 400 bad request as error message by default. 


If you hit same api in postman it will give detailed error message. To capture that error message go to on after response and use exception handler to get that detailed error response "CustomizedResponse.ResponseText"


I achieved your need like this already

Regards

Murali

2025-01-09 14-56-57
IQ78

hi, thanks

 I tried yours and it is correct that in the Restponse text there it the detail, although statusCode only 400 :

And when i catch the exception, why only return only StatusLine:"400 Bad Request", not all the detail:

regards


2024-05-02 09-49-04
Murali Manoharan V
Champion

Hi @ibox 

if it helps you please mark this answer as solution, it will help others in future also


Regards

Murali

2019-09-30 07-35-56
Aurelio Junior
Solution

Hello,

OutSystems automatically throws an exception whenever a REST API returns a status code in the 400 range, which prevents you from getting the error details in the API method's response. You can work around this though. First of all, make sure you have an error output parameter in your consumed REST method. You can use the "Test" tab to automatically generate this by intentionally making a request that results in an error and then copying the response to the body:

Then, you can use the API's "OnAfterResponse" callback to manually override the status code, preventing the platform from automatically throwing an exception. Something like this:

Be advised that this will mask all 400 errors returned by your consumed API, so you have to make sure to always check the method's response for errors after calling it.

2025-01-09 14-56-57
IQ78

Hi, thanks

So, after it is OK, we capture the error inside a local variable?

regards

2019-09-30 07-35-56
Aurelio Junior

Yes, you can look into the API method's response to get the error message. Something like this:


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.