---
title: "Fastify Error Handler"
description: "Learn how Sentry's Fastify integration captures errors and how to configure it."
url: https://docs.sentry.io/platforms/javascript/guides/fastify/features/error-handler/
---

# Fastify Error Handler | Sentry for Fastify

The `fastifyIntegration` captures errors in your Fastify application and sends them to Sentry. It's enabled by default, so you only need to add it to your `Sentry.init` call to configure it.

By default, errors with status codes 5xx and above, as well as errors with status codes 2xx and below, are captured. Errors with 3xx and 4xx status codes aren't sent to Sentry.

## [Configuration](https://docs.sentry.io/platforms/javascript/guides/fastify/features/error-handler.md#configuration)

To control which errors are captured, pass `shouldHandleError` to `Sentry.fastifyIntegration`:

```javascript
import * as Sentry from "@sentry/node";

Sentry.init({
  dsn: "your-dsn",
  integrations: [
    Sentry.fastifyIntegration({
      shouldHandleError(error, request, reply) {
        return reply.statusCode >= 500;
      },
    }),
  ],
});
```

## [Options](https://docs.sentry.io/platforms/javascript/guides/fastify/features/error-handler.md#options)

`Sentry.fastifyIntegration` accepts the following options:

* `shouldHandleError`

A function that determines whether an error should be captured.

```typescript
declare function shouldHandleError(
  error: Error,
  request: FastifyRequest,
  reply: FastifyReply,
): boolean;
```

If using TypeScript, you can cast the request and reply to get full type safety.

```typescript
import type { FastifyRequest, FastifyReply } from "fastify";

Sentry.fastifyIntegration({
  shouldHandleError(error, minimalRequest, minimalReply) {
    const request = minimalRequest as FastifyRequest;
    const reply = minimalReply as FastifyReply;
    return reply.statusCode >= 500;
  },
});
```
