Change Return Messages Rest

0
Good morning everyone, I would like to know if it is possible to change return messages from a rest service I created. When I receive a post request, the import mapping validates the request data and any error occurs it returns an error message in json format I would like to know if I can customize this return message. In the image below, the client with id 10 does not exist in the database and so I would like to put in the return message which field is in error to facilitate the understanding of the service consumer. I tried to create a microflow to validate and return a custom error message, but the microflow is only executed if all the data arrives correctly, that is, this validation seems to be carried out by the import mapping.    
asked
4 answers
0

Maybe error handling can help you out:

 

answered
0

Good afternoon Tom, first thank you for your contribution. In my case I'm exposing an api and not consuming this solution so I believe I couldn't solve the problem. I would be able to apply something without

answered
0

You can but you will loose a piece of Mendix magic.

Your service usually takes care of three steps: import mapping, calling the microflow, the export mapping.

Instead of having your service take care of the import mapping, make it pass the request-content as a string.  Your microflow can do the import-mapping, the Client’s ‘find by key’ will result in an error, so in your microflow set error-handling on the import-mapping activity. On handling the error, change HttpResponse (that you need to have as import parameter of the microflow). Set HttpResponse/Message to whatever you like.

** Editted ** Well, actually, yes you can do this the way you like, if set the mapping instead of Error, to Ignore.

You will get to your microflow and in your microflow, if you have no associated client, set the HttpMessage like I described above.

 

answered
0

Good afternoon Tim, thanks for the reply. Got it, so using Mendix's default import mapping I wouldn't be able to change the return message?


Graciously,

josimar

answered