When a REST API method runs into an error, it's useful to send a meaningful error message to the client about what happened. Some of the problems are automatically handled for you by the OutSystems, but you have the possibility to add custom error handling to your logic.
OutSystems will automatically handle the following errors:
- Invalid requests;
- Unhandled exceptions during the execution of the REST API method’s action flow.
If you want to add a custom error that appears in the response body, do the following:
- Create a new User Exception;
- Raise the user exception in your REST API method:
- Add a Raise Error element to the action flow of the REST API method;
- In the Exception property, set it to raise the User Exception you have created in 1;
- Set the Exception Message property to your custom error message.