# HTTP Client Errors | Sentry for iOS

Once enabled, this feature automatically captures HTTP client errors, like bad response codes, as error events and reports them to Sentry. The error event will contain the `request` and `response` data, such as `url`, `status_code`, and so on. Depending on your HTTP request setup, it can happen that the stacktrace of these events doesn't pinpoint the exact location of the HTTP request in your code. If that's the case, you can look at the HTTP request info of the issue, which contains things like URL and HTTP headers.

Since 8.0.0, this feature has been enabled by default. To disable it:

```swift
import Sentry

SentrySDK.start { options in
    options.dsn = "https://examplePublicKey@o0.ingest.sentry.io/0"
    options.enableCaptureFailedRequests = false
}
```

By default, only HTTP client errors with a response code between `500` and `599` are captured as error events, but you can change this behavior by setting the `failedRequestStatusCodes` option:

```swift
import Sentry

SentrySDK.start { options in
    options.dsn = "https://examplePublicKey@o0.ingest.sentry.io/0"
    let httpStatusCodeRange = HttpStatusCodeRange(min: 400, max: 599)
    options.failedRequestStatusCodes = [ httpStatusCodeRange ]
}
```

HTTP client errors from every target (`.*` regular expression) are automatically captured, but you can change this behavior by setting the `failedRequestTargets` option with either a regular expression or a plain `String`. A plain string must contain at least one of the items from the list. Plain strings don't have to be full matches, meaning the URL of a request is matched when it contains a string provided through the option:

```swift
import Sentry

SentrySDK.start { options in
    options.dsn = "https://examplePublicKey@o0.ingest.sentry.io/0"
    options.failedRequestTargets = [ "www.example.com" ]
}
```

Error events may contain PII data, such as `Headers` and `Cookies`. Sentry already does data scrubbing by default, but you can scrub any data before it is sent. Learn more in [Scrubbing Sensitive Data](https://docs.sentry.io/platforms/apple/guides/ios/data-management/sensitive-data.md).

These events are searchable and you can set alerts on them if you use the `http.url` and `http.status_code` properties. Learn more in our full [Searchable Properties](https://docs.sentry.io/concepts/search/searchable-properties.md) documentation.

### [Customize or Drop the Error Event](https://docs.sentry.io/platforms/apple/guides/ios/configuration/http-client-errors.md#customize-or-drop-the-error-event)

The captured error event can be customized or dropped with a `beforeSend`:

```swift
import Sentry

SentrySDK.start { options in
    options.dsn = "https://examplePublicKey@o0.ingest.sentry.io/0"
    options.beforeSend = { event in
        // modify event here or return nil to discard the event
        return event
    }
}
```
