# Handling Errors

Each [API](/gravity-server/rest-api.md) controller method call is wrapped in a HOF (higher-order function) called `use`**.**

```javascript
// node.js
api.post('/api/account', use(accountController.create));

// next.js
export const GET = withApiRoute('owner', 'account.read', accountController.get);
```

This is a middleware function that catches any errors in the controller methods and then passes these to a global error handler. This prevents you from having to use `try...catch` in your application.

When an error is caught, it will be logged to the console and a 500 status message returned to the client along with the error message.&#x20;

{% hint style="info" %}
Errors are [automatically logged](/gravity-server/logging.md) and accessible any time in [Mission Control](/mission-control/introduction.md).
{% endhint %}

Please refer to the error handling section in [Gravity Web](/gravity-web/handling-errors.md) or [Gravity Native](/gravity-native/handling-errors.md) to understand how these errors are handled on the client side.&#x20;


---

# Agent Instructions: 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:

```
GET https://docs.usegravity.app/gravity-server/handling-errors.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
