# Handling Errors

Each [API](https://docs.usegravity.app/gravity-server/rest-api) 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](https://docs.usegravity.app/gravity-server/logging) and accessible any time in [Mission Control](https://docs.usegravity.app/mission-control/introduction).
{% endhint %}

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