> For the complete documentation index, see [llms.txt](https://nanoexpress.js.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nanoexpress.js.org/routes/errors-handling.md).

# Errors handling

{% hint style="info" %}
Node.js v13.5+ new argument params help you trace warnings and errors

* `--trace-uncaught`
* `--trace-warnings`

Example, `node --trace-uncaught server.js`
{% endhint %}

## Error handling

{% hint style="warning" %}
Only **async** route functions and middlewares are handled
{% endhint %}

```typescript
app.setErrorHandler(
  (err: Error, req: HttpRequest, res: HttpResponse): HttpResponse => {
    if (checkSomething(err)) {
      return res.send({
        status: 'error',
        status_code: 500,
        message: 'oops'
      })
    }
  }
);
```

<mark style="color:blue;">`GET`</mark> `http://localhost:8000/error-route`

#### Path Parameters

| Name | Type   | Description |
| ---- | ------ | ----------- |
|      | string |             |

{% tabs %}
{% tab title="200 " %}

```
```

{% endtab %}
{% endtabs %}

## Not found handler

```typescript
app.setNotFoundHandler((req: HttpRequest, res: HttpResponse): HttpResponse => {
    return res.send({ code: 404, message: 'You entered wrong url' });
});
```

<mark style="color:blue;">`GET`</mark> `http://localhost:8000/anyUrl`

#### Path Parameters

| Name | Type   | Description |
| ---- | ------ | ----------- |
|      | string |             |

{% tabs %}
{% tab title="200 " %}

```
```

{% endtab %}
{% endtabs %}

## Validation error handler

{% hint style="warning" %}
Validation error handler unavailable for **pro-slim** version
{% endhint %}

```typescript
app.setValidationErrorHandler((errors: AjvValidationErrors[], req: HttpRequest, res: HttpResponse): HttpResponse => {
    return res.json({ errors });
});
```

<mark style="color:blue;">`GET`</mark> `http://locahost:8000/validate-error`

#### Request Body

| Name | Type   | Description |
| ---- | ------ | ----------- |
| foo  | string | bar         |

{% tabs %}
{% tab title="400 " %}

```
{
  "errors": {
    "type": "errors",
    "errors": [
      {
        "body": ["type should be string, but got ..."]
      }
    ]
  }
}
```

{% endtab %}
{% endtabs %}
