---
title: Track failing HTTP transactions
source: https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/network-request-failures
---

## Android

### Syntax [#syntax]

#### Java [#java]

```java
NewRelic.noticeNetworkFailure(string $url, string $httpMethod, long $startTime, long $endTime, exception $exception OR enum $networkFailure)
```

#### Kotlin [#kotlin]

```kotlin
NewRelic.noticeNetworkFailure(
    url: String?,
    httpMethod: String?,
    startTime: Long,
    endTime: Long,
    failure: NetworkFailure?,
)
```

### Description [#description]

The New Relic Android SDK API provides several methods to [track network requests](https://docs.newrelic.com/docs/mobile-monitoring/new-relic-mobile/mobile-sdk/network-request-success/). If a network request fails, you can record details about the failure with `noticeNetworkFailure`. In most cases, place this call inside exception handlers, such as catch blocks.

### Parameters [#parameters]

| Parameter     | Type     | Description                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `$url`        | `string` | Required. The URL of the request.                                                                                                                                                                                                                                                                                                                                                                                                          |
| `$httpMethod` | `string` | Required. The HTTP method used, such as GET or POST.                                                                                                                                                                                                                                                                                                                                                                                       |
| `$startTime`  | `long`   | Required. The start time of the request in milliseconds since the epoch.                                                                                                                                                                                                                                                                                                                                                                   |
| `$endTime`    | `long`   | Required. The end time of the request in milliseconds since the epoch.                                                                                                                                                                                                                                                                                                                                                                     |
| `$exception`  | `string` | Either this or `$failure` parameter is required. This is the exception that occurred. New Relic can automatically translate many common exceptions into network failure types.                                                                                                                                                                                                                                                             |
| `$failure`    | `enum`   | Either this or `$exception` parameter is required. The type of network failure that occurred. If an exception cannot be resolved to a network failure automatically, this method can be used to categorize the failure accurately. The values are defined by the `NetworkFailure` enum. Valid values include `Unknown`, `BadURL`, `TimedOut`, `CannotConnectToHost`, `DNSLookupFailed`, `BadServerResponse`, and `SecureConnectionFailed`. |

### Examples [#examples]

Here’s an example of an error listener that uses an error as part of the noticed network failure to New Relic:

#### Java [#java]

```java
new Response.ErrorListener() {
  @Override
  public void onErrorResponse(Error error) {
    NewRelic.noticeNetworkFailure(badUrl, "GET", System.nanoTime(),
        System.nanoTime(), NetworkFailure.exceptionToNetworkFailure(error));
  }
}
```

#### Kotlin [#kotlin]

```kotlin
NewRelic.noticeNetworkFailure(
    badUrl,
    "GET",
    System.nanoTime(),
    System.nanoTime(),
    NetworkFailure.exceptionToNetworkFailure(error)
)
```

## iOS

### Syntax [#syntax]

#### Objective-c [#objc]

```objectivec
+ (void)noticeNetworkFailureForURL:(NSURL*)url
                        httpMethod:(NSString*)httpMethod
                         withTimer:(NRTimer*)timer
                    andFailureCode:(NSInteger)iOSFailureCode;
```

#### Swift [#swift]

```swift
func noticeNetworkFailure(for: URL, httpMethod: String, with: NRTimer, andFailureCode: Int)
```

### Description [#description]

Failed requests are requests that fail to receive a complete response from
the server caused by things like TCP timeouts, SSL failures, connection closures, and more.

### Parameters [#parameters]

| Parameter         | Type        | Description                                                                                                                                                                                                                |
| ----------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `$url`            | `NSURL`     | Required. The URL of the request.                                                                                                                                                                                          |
| `$httpMethod`     | `string`    | Required. The HTTP method of the request.                                                                                                                                                                                  |
| `$timer`          | `NRTimer`   | Required. A timer that captures the start and end of the request.                                                                                                                                                          |
| `$iOSFailureCode` | `NSInteger` | Required. The failure codes you pass into this method should correlate to [Apple's documented NSURLConnection failure codes](https://developer.apple.com/documentation/foundation/1508628-url_loading_system_error_codes). |

### Examples [#examples]

#### Objective-C [#obj-c]

```objectivec
[NewRelic noticeNetworkFailureForURL:[NSURL URLWithString:@"https://www.newrelic.com"]
                          httpMethod:@"GET"
                           withTimer:[[NRTimer alloc] init]
                      andFailureCode:NSURLErrorTimedOut];
```

#### Swift

```swift
NewRelic.noticeNetworkFailure(for: URL(string: "https://www.newrelic.com"), httpMethod: "GET",
                              with: NRTimer(), andFailureCode: NSURLErrorTimedOut)
```

## Cordova

### Syntax [#syntax]

```typescript
noticeNetworkFailure(url: string, httpMethod: string, startTime: number, endTime: number, failure: string): void;
```

### Description [#description]

Records network failures. If a network request fails, use this method to record details about the failures.

### Parameters [#parameters]

| Parameter    | Type     | Description                                                                                                                                                                                                                                 |
| ------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `url`        | `string` | Required. The URL of the request.                                                                                                                                                                                                           |
| `httpMethod` | `string` | Required. The HTTP method of the request.                                                                                                                                                                                                   |
| `startTime`  | `number` | Optional. The start time of the request in milliseconds since the epoch. `startTime` and `endTime` can be used as an alternative to `timer`.                                                                                                |
| `endTime`    | `number` | Optional. The end time of the request in milliseconds since the epoch. `startTime` and `endTime` can be used as an alternative to `timer`.                                                                                                  |
| `failure`    | `string` | Optional. In most cases, place this call inside exception handlers, such as catch blocks. Supported failures are: `Unknown`, `BadURL`, `TimedOut`, `CannotConnectToHost`, `DNSLookupFailed`, `BadServerResponse`, `SecureConnectionFailed`. |

### Example [#example]

```js
NewRelic.noticeNetworkFailure('https://fakewebsite.com', 'GET', Date.now(), Date.now(), 'BadURL');
```

## .NET MAUI

### Syntax [#syntax]

```csharp
void NoticeNetworkFailure(string url, string httpMethod, long startTime, long endTime, NetworkFailure failure);
```

### Description [#description]

Records network failures. If a network request fails, use this method to record details about the failure.

### Parameters [#parameters]

| Parameter    | Type     | Description                                                                                                                                                                                                                                 |
| ------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `url`        | `string` | Required. The URL of the request.                                                                                                                                                                                                           |
| `httpMethod` | `string` | Required. The HTTP method of the request.                                                                                                                                                                                                   |
| `startTime`  | `number` | Optional. The start time of the request in milliseconds since the epoch. `startTime` and `endTime` can be used as an alternative to `timer`.                                                                                                |
| `endTime`    | `number` | Optional. The end time of the request in milliseconds since the epoch. `startTime` and `endTime` can be used as an alternative to `timer`.                                                                                                  |
| `failure`    | `string` | Optional. In most cases, place this call inside exception handlers, such as catch blocks. Supported failures are: `Unknown`, `BadURL`, `TimedOut`, `CannotConnectToHost`, `DNSLookupFailed`, `BadServerResponse`, `SecureConnectionFailed`. |

### Example [#example]

```csharp
CrossNewRelic.Current.NoticeNetworkFailure(
  "https://fakewebsite.com",
  "GET",
  DateTimeOffset.Now.ToUnixTimeMilliseconds(),
  DateTimeOffset.Now.ToUnixTimeMilliseconds() + 100,
  NetworkFailure.Unknown
);
```

## Flutter

### Syntax [#syntax]

```dart
noticeNetworkFailure(String url, String httpMethod, int startTime, int endTime, NetworkFailure errorCode): void;
```

### Description [#description]

Records network failures. If a network request fails, use this method to record details about the failures.

### Parameters [#parameters]

| Parameter    | Type              | Description                                                                                                                                                                                                                                 |
| ------------ | ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `url`        | `string`          | Required. The URL of the request.                                                                                                                                                                                                           |
| `httpMethod` | `string`          | Required. The HTTP method of the request.                                                                                                                                                                                                   |
| `startTime`  | `int`             | Optional. The start time of the request in milliseconds since the epoch. `startTime` and `endTime` can be used as an alternative to `timer`.                                                                                                |
| `endTime`    | `int`             | Optional. The end time of the request in milliseconds since the epoch. `startTime` and `endTime` can be used as an alternative to `timer`.                                                                                                  |
| `errorCode`  | `network failure` | Required. In most cases, place this call inside exception handlers, such as catch blocks. Supported failures are: `Unknown`, `BadURL`, `TimedOut`, `CannotConnectToHost`, `DNSLookupFailed`, `BadServerResponse`, `SecureConnectionFailed`. |

### Example [#example]

```dart
NewrelicMobile.instance.noticeNetworkFailure("https://cb6b02be-a319-4de5-a3b1-361de2564493.mock.pstmn.io/searchpage", "GET", 1000, 2000,'Test Network Failure', NetworkFailure.dnsLookupFailed);
```

## React Native

### Syntax [#syntax]

```js
noticeNetworkFailure(url: string, httpMethod: string, startTime: number, endTime: number, failure: string): void;
```

### Description [#description]

Records network failures. If a network request fails, use this method to record details about the failures. In most cases, place this call inside exception handlers, such as catch blocks.

### Parameters [#parameters]

| Parameter    | Type     | Description                                                                                                                                                                                                                                 |
| ------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `url`        | `string` | Required. The URL of the request.                                                                                                                                                                                                           |
| `httpMethod` | `string` | Required. The HTTP method of the request.                                                                                                                                                                                                   |
| `startTime`  | `number` | Optional. The start time of the request in milliseconds since the epoch. `startTime` and `endTime` can be used as an alternative to `timer`.                                                                                                |
| `endTime`    | `number` | Optional. The end time of the request in milliseconds since the epoch. `startTime` and `endTime` can be used as an alternative to `timer`.                                                                                                  |
| `failure`    | `string` | Required. In most cases, place this call inside exception handlers, such as catch blocks. Supported failures are: `Unknown`, `BadURL`, `TimedOut`, `CannotConnectToHost`, `DNSLookupFailed`, `BadServerResponse`, `SecureConnectionFailed`. |

### Example [#example]

```js
NewRelic.noticeNetworkFailure('https://github.com', 'GET', Date.now(), Date.now(), NewRelic.NetworkFailure.BadURL);
```

## Xamarin

### Syntax [#syntax]

```csharp
NoticeNetworkFailure(string url, string httpMethod, long startTime, long endTime, NetworkFailure failure)
```

### Description [#description]

Records network failures. If a network request fails, use this method to record details about the failure.

### Parameters [#parameters]

| Parameter    | Type     | Description                                                                                                                                                                                                                                 |
| ------------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `url`        | `string` | Required. The URL of the request.                                                                                                                                                                                                           |
| `httpMethod` | `string` | Required. The HTTP method of the request.                                                                                                                                                                                                   |
| `startTime`  | `number` | Optional. The start time of the request in milliseconds since the epoch. `startTime` and `endTime` can be used as an alternative to `timer`.                                                                                                |
| `endTime`    | `number` | Optional. The end time of the request in milliseconds since the epoch. `startTime` and `endTime` can be used as an alternative to `timer`.                                                                                                  |
| `failure`    | `string` | Optional. In most cases, place this call inside exception handlers, such as catch blocks. Supported failures are: `Unknown`, `BadURL`, `TimedOut`, `CannotConnectToHost`, `DNSLookupFailed`, `BadServerResponse`, `SecureConnectionFailed`. |

### Example [#example]

```csharp
CrossNewRelicClient.Current.NoticeNetworkFailure(
  "https://fakewebsite.com",
  "GET",
  DateTimeOffset.Now.ToUnixTimeMilliseconds(),
  DateTimeOffset.Now.ToUnixTimeMilliseconds() + 100,
  NetworkFailure.Unknown
);
```
