NetworkException


abstract class NetworkException : HttpException
kotlin.Any
   ↳ kotlin.Throwable
   ↳ java.lang.Exception
   ↳ java.io.IOException
   ↳ android.net.http.HttpException
   ↳ android.net.http.NetworkException

Exception passed to UrlRequest.Callback.onFailed() when the HTTP stack fails to process a network request. In this case getErrorCode can be used to get more information about the specific type of failure.

Summary

Constants
static Int

Error code indicating the IP address being contacted is unreachable, meaning there is no route to the specified host or network.

static Int

Error code indicating the connection was closed unexpectedly.

static Int

Error code indicating the connection attempt was refused.

static Int

Error code indicating the connection was unexpectedly reset.

static Int

Error code indicating the connection attempt timed out.

static Int

Error code indicating the host being sent the request could not be resolved to an IP address.

static Int

Error code indicating the device was not connected to any network.

static Int

Error code indicating that as the request was processed the network configuration changed.

static Int

Error code indicating another type of error was encountered.

static Int

Error code indicating an error related to the QUIC protocol.

static Int

Error code indicating a timeout expired.

Public constructors
NetworkException(message: String?, cause: Throwable?)

Constructs an exception that is caused by a network error.

Public methods
abstract Int

Returns error code, one of ERROR_*.

abstract Boolean

Returns true if retrying this request right away might succeed, false otherwise.

Constants

ERROR_ADDRESS_UNREACHABLE

static val ERROR_ADDRESS_UNREACHABLE: Int

Error code indicating the IP address being contacted is unreachable, meaning there is no route to the specified host or network.

Value: 9

ERROR_CONNECTION_CLOSED

static val ERROR_CONNECTION_CLOSED: Int

Error code indicating the connection was closed unexpectedly.

Value: 5

ERROR_CONNECTION_REFUSED

static val ERROR_CONNECTION_REFUSED: Int

Error code indicating the connection attempt was refused.

Value: 7

ERROR_CONNECTION_RESET

static val ERROR_CONNECTION_RESET: Int

Error code indicating the connection was unexpectedly reset.

Value: 8

ERROR_CONNECTION_TIMED_OUT

static val ERROR_CONNECTION_TIMED_OUT: Int

Error code indicating the connection attempt timed out.

Value: 6

ERROR_HOSTNAME_NOT_RESOLVED

static val ERROR_HOSTNAME_NOT_RESOLVED: Int

Error code indicating the host being sent the request could not be resolved to an IP address.

Value: 1

ERROR_INTERNET_DISCONNECTED

static val ERROR_INTERNET_DISCONNECTED: Int

Error code indicating the device was not connected to any network.

Value: 2

ERROR_NETWORK_CHANGED

static val ERROR_NETWORK_CHANGED: Int

Error code indicating that as the request was processed the network configuration changed. When getErrorCode returns this code, this exception may be cast to QuicException for more information if QUIC protocol is used.

Value: 3

ERROR_OTHER

static val ERROR_OTHER: Int

Error code indicating another type of error was encountered.

Value: 11

ERROR_QUIC_PROTOCOL_FAILED

static val ERROR_QUIC_PROTOCOL_FAILED: Int

Error code indicating an error related to the QUIC protocol. When getErrorCode returns this code, this exception can be cast to QuicException for more information.

Value: 10

ERROR_TIMED_OUT

static val ERROR_TIMED_OUT: Int

Error code indicating a timeout expired. Timeouts expiring while attempting to connect will be reported as the more specific ERROR_CONNECTION_TIMED_OUT.

Value: 4

Public constructors

NetworkException

NetworkException(
    message: String?,
    cause: Throwable?)

Constructs an exception that is caused by a network error.

Parameters
message String?: explanation of failure. This value may be null.
cause Throwable?: the cause (which is saved for later retrieval by the getCause() method). A null value is permitted, and indicates that the cause is nonexistent or unknown.

Public methods

getErrorCode

abstract fun getErrorCode(): Int

Returns error code, one of ERROR_*.

Return
Int error code, one of ERROR_*.

isImmediatelyRetryable

abstract fun isImmediatelyRetryable(): Boolean

Returns true if retrying this request right away might succeed, false otherwise. For example returns true when getErrorCode returns ERROR_NETWORK_CHANGED because trying the request might succeed using the new network configuration, but false when getErrorCode() returns ERROR_INTERNET_DISCONNECTED because retrying the request right away will encounter the same failure (instead retrying should be delayed until device regains network connectivity).

Return
Boolean true if retrying this request right away might succeed, false otherwise.