• /
  • Log in
  • Free account

noticeNetworkFailure (Android SDK API)

Syntax

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

Records network failures.

Requirements

Compatible with all agent versions.

Description

The New Relic Android SDK API provides several methods to track network requests. 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.

For general info on using the New Relic Android SDK API, see the usage guide.

Parameters

Parameter

Description

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

$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

Record network failure

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

new Response.ErrorListener() {
@Override
public void onErrorResponse(Error error) {
NewRelic.noticeNetworkFailure(badUrl, "GET", System.nanoTime(), System.nanoTime(), NetworkFailure.exceptionToNetworkFailure(error));
}
Create issueEdit page
Copyright © 2022 New Relic Inc.