Creating Custom Error Responses
Last updated
Last updated
Custom error responses can enhance user experience by providing clear and specific feedback. In this guide, we'll demonstrate how to create custom error responses using Cosmocloud's Flow Builder.
The Build JSON node allows you to construct a custom JSON object for your error response.
Add the **Build JSON** node to your flow.
Open the node properties.
Configure the name of the JSON object and its initial value. For instance, to return an error message {'msg': 'record not found'}
, set the variable name to errorResponse
.
You can now use the custom JSON object in the HTTP Response node to send your custom error response.
Open the properties panel of the HTTP Response node.
Set the response value to $.variables.<created variable>
. For example, use $.variables.errorResponse
.
Select the corresponding status code from the drop-down menu, such as 404 - Not Found
.
This node now will return the response body as defined in the Build JSON node and the response status as 404.