When consuming a REST API method, if the service returns an HTTP error status code (400 and above), OutSystems throws an exception. This allows you to handle the REST API error by implementing your own logic.
To handle a REST API error, do the following:
Add an Exception Handler in the logic that uses the REST API method, and set the Exception Handler to catch
Implement the logic to handle the error, like displaying a message to the end-user.
Processing the Response
For situations that require a higher degree of control over the REST API method response, OutSystems allows you to access the original HTTP response, analyze the original values sent by the REST service, such as the status code or the headers, and manipulate them to your needs. You can achieve this doing one of the following:
- a simple customization using the OnAfterResponse callback
- an advanced customization using the OnAfterResponseAdvanced callback
Since these actions run before OutSystems processes the REST response, if you change the status code of the response to success (200), OutSystems no longer raises an exception.