> For the complete documentation index, see [llms.txt](https://sevenval.gitbook.io/flat/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sevenval.gitbook.io/flat/develop/reference/actions/error.md).

# error Action

The `error` action provides a simple and consistent way to handle errors throughout the configuration.

It terminates the flow, sets its body template result as [`$error`](/flat/develop/reference/variables.md#usderror) and calls the [error flow](/flat/develop/reference/openapi-4/routing.md#error-flow), if configured, or sends the [system error document](/flat/develop/reference/openapi-7/validation.md#system-error-document) with the body template result as the value of the `error` property.

In its simplest form, an error is triggered like this:

```markup
<error/>
```

To make errors more useful, they should contain a message:

```markup
<error>
{
  "message": "Upstream system sent unusable data"
}
</error>
```

## Error Properties

The action body contains a constant JSON string or a [JSON template](/flat/develop/reference/templating.md) representing a JSON object. The object will be assigned to the `$error` variable.

The following properties of the `$error` object are optional, but must have the specified type if set. If not set, they will receive the following default values:

* `message`: `string`, default: `'FlowError'`
* `status`: `integer` between 100 and 599, default: `500`
* `code`: `integer` between 0 and 9999, default: `5000`
* `info`: `array` of `string`, default: `["Flow Error triggered"]`

Additional properties are allowed. They will be accessible in the Error Flow. The following example includes the URL in `$error/url`:

```markup
<error>
{
  {{: $request/url }}
  "message": "Upstream system sent unusable data",
  "status": 502,
  "code": 4711
}
</error>
```

## Status Code

The `status` property will be used as the HTTP response status code. The status code may alternatively be defined with the optional `status` attribute.

```markup
<error status="403"/>
```

```markup
<error status="502">
{
  "message": "Upstream system sent unusable data"
}
</error>
```

## Fixed message shortcut

If the action body is a string constant (it must be enclosed in double quotes), its value will be assigned to the `$error/message` property. This is a handy shortcut to trigger simple errors with fixed messages:

```markup
<error status="502"> "Upstream system sent unusable data" </error>
```

## Logging

The `error` emits an [error log](/flat/develop/administration/logging.md#error-log) event with the `error` topic and the given `message`:

```javascript
{
  "timestamp": "2020-05-19T16:27:46+00:00",
  "type": "flat_alert",
  "requestID": "XsQJAMvNgp1P2qKAxKmdaAAAAAI",
  "topic": "error",
  "message": "Upstream system sent unusable data"
}
```

## See also

* [Error Flow](/flat/develop/reference/openapi-4/routing.md#error-flow)
* [`$error`](/flat/develop/reference/variables.md#usderror)
* [Handling Errors](/flat/develop/cookbook/error-flow.md) (Cookbook)


---

# 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://sevenval.gitbook.io/flat/develop/reference/actions/error.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.
