interface NetworkError

Networking Error

The shape of Error objects delivered to networking 'error' callbacks and promise rejections across fetch(), the net/tls/dgram modules, the http/https modules, WebSocket, and EventSource.

These are ordinary JavaScript Error instances with extra properties describing the failure; any individual property may be absent depending on the failure category.

Recognized code values include the Node-style codes EACCES, EADDRINUSE, EADDRNOTAVAIL, EAGAIN, ECANCELED, ECONNABORTED, ECONNREFUSED, ECONNRESET, EHOSTUNREACH, EINVAL, EMFILE, ENETDOWN, ENETUNREACH, ENOENT, ENOMEM, ENOTCONN, ENOTFOUND, ENOTSOCK, EPERM, EPIPE, and ETIMEDOUT, plus internal codes such as ABORT_ERR, ERR_INVALID_URL, ERR_SOCKET_CLOSED, ERR_TLS_CONTEXT, ERR_TLS_SNI, ERR_CONTENT_DECODING, ERR_HTTP_CONTENT_LENGTH_MISMATCH, and ERR_SSL. Unknown categories leave code unset.

Example

socket.on("error", (err) => {
  if (err.code === "ECONNREFUSED") {
    // retry or report
  }
});

Index

Properties

address string

Remote address when relevant (e.g. TCP connect or fetch DNS resolution).

code string

Node-style error code when known, e.g. "ECONNREFUSED", "ETIMEDOUT".

errno string

Mirror of NetworkError.code for Node compatibility.

port number

Remote port when relevant.

syscall string

The operation that failed, e.g. "connect", "listen", "read", "write".