Thanks。
I read the document. But, it doesn’t solve my confustion.
Yes, if i want to do some error handling or log error messges or display error messge on web or native page, It is fine.
But, I am using a Java Native Android app to call the rest api published by mendix app.
When use on app input some values , I will post the data to mendix api. If everything is ok, the rest will return the new create entity data. If some logic error( this by logic,not only data validation) , Client app expect to recieve a error code and messge, the messge will show on 3re Android app to user.
The problem is: The common return format is different with error message.
eg.
Common return:
{
rfid:000232,
matcode:”sdf”,
weighting:99
}
But if error happen
it should return:
{ "error": { "code": 500, "message": "Operation fail, the reason is:XXXXXXXXXX" } }
If any place where i can change the message content before return response to client?
- When you create the REST service and attach a Microflow, the Response type for the service will be String, so you should send only string
- But normally what I follow is, I make the Microflow return HTTP response instead of String, so in the service the Response type will be changed to HTTPResponse. See the Green box in the image below.
- This also gave me the flexibility of changing the Error code. So for specific errors, I returned Specific messages along with appropriate error code (attached the Microflow as well)
- In the below Sub microflow, I created HTTP response and attached it to the HTTP header object.
- The reason phrase will be like the title and content will be actual JSON
- Errorcode can be set on the status code in HTTP response
You can set custom error handling on your integration activities, file a custom log message and send a custom message to the user
some background:
https://docs.mendix.com/howto/logic-business-rules/set-up-error-handling