> For the complete documentation index, see [llms.txt](https://docs.cosmocloud.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cosmocloud.io/examples-how-to/creating-custom-error-responses.md).

# 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.<br>

### Step 1: Use the [Build Json](/flow-builder/node-types/variable-nodes/json/build-json-object.md)   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.

<figure><img src="https://lh7-us.googleusercontent.com/docsz/AD_4nXeI3jqe-stnS9pfB2qICs1J9DwgLvkaUiiX1vgP9655EXhngn2uA5U8-sZwv-0g6xwT8dLPIfS35G5Mi4JDUM8mq5sl57spEfSmDUkHKy-716x2BjfS_a9jT0Ddks_Okmptq4JpG1C_3SMtm4W8Uvv0nsoC?key=lioysNCrnRX1UpiKiuyFyw" alt=""><figcaption></figcaption></figure>

2. &#x20;Open the node properties.

<figure><img src="https://lh7-us.googleusercontent.com/docsz/AD_4nXeMQ67YfcH9maQJq2xcrFHBOcKYUVEgeTqabRPpL0SVsCM1AO7DL5WTtEMxfg5Kq0oj8F3jbhuqV-FqwygGfJvDRNls_dtADqhROzHFe2QkDAA27iP--t6KVFayrG8M4uzUgSZZ7iTXA287NG_1f7Q_C6GK?key=lioysNCrnRX1UpiKiuyFyw" alt=""><figcaption></figcaption></figure>

3. &#x20;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`.

<figure><img src="https://lh7-us.googleusercontent.com/docsz/AD_4nXcnvWkc626wqTQHdl8Gf2_CtqPbNCPS2kucHcPhwAanrqqC5VLGcN1aSiYMg1SMZnRYo9JeWyCIi8zW03Z2e18p-WoY1mtHoQaJiEiGihIY_O_N9zCpJ1a-MqwBLKCGyIRtXg44UNWRZoAo3PS6v4mkawiD?key=lioysNCrnRX1UpiKiuyFyw" alt=""><figcaption></figcaption></figure>

### 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`.

<figure><img src="https://lh7-us.googleusercontent.com/docsz/AD_4nXeb_iHkTz5BoxdbFUdQdWeaNNO9ZBbzxxE78QLS3NgqqBwGxdQw8ZyU4PZyI6De3RKhdMNXdgZQdVxelmZMJ7eV37nLqF1VWVkPpujrfDsovi0Hbgp9iulmAiyguuAOGWdDHaDfNmERYQfKVhaXZhkzkLBo?key=lioysNCrnRX1UpiKiuyFyw" alt=""><figcaption></figcaption></figure>

<br>

This node now will return the response body as defined in the Build JSON node and the response status as 404.

<br>

<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.cosmocloud.io/examples-how-to/creating-custom-error-responses.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
