Creating Custom Error Responses

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.

Step 1: Use the Build Json node

The Build JSON node allows you to construct a custom JSON object for your error response.

  1. Add the **Build JSON** node to your flow.

  1. Open the node properties.

  1. 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.

Step 2: Use the HTTP Response Node

You can now use the custom JSON object in the HTTP Response node to send your custom error response.

  1. Open the properties panel of the HTTP Response node.

  2. Set the response value to $.variables.<created variable>. For example, use $.variables.errorResponse.

  3. 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.

Last updated