API Reference

RezoError

RezoError provides structured error information including error codes, HTTP status details, boolean classification flags, and recovery suggestions. All Rezo operations throw RezoError instances on failure.

Constructor

new RezoError<T = any>(
  message: string,
  config: RezoConfig,
  code?: RezoErrorCodeString,
  request?: RezoHttpRequest,
  response?: RezoResponse<T>
)
ParameterTypeDescription
messagestringHuman-readable error message. Overridden by ERROR_INFO lookup if code is provided.
configRezoConfigThe request configuration that produced this error.
codeRezoErrorCodeStringError code string (e.g., 'ECONNREFUSED', 'REZ_HTTP_ERROR').
requestRezoHttpRequestThe underlying request object, if available.
responseRezoResponse<T>The HTTP response, if one was received before the error.

Example

import { RezoError, RezoErrorCode } from 'rezo';

try {
  await rezo.get('https://unreachable.example.com');
} catch (err) {
  if (err instanceof RezoError) {
    console.log(err.code);       // "ECONNREFUSED"
    console.log(err.message);    // "Connection Refused"
    console.log(err.suggestion); // "Verify the server is running..."
  }
}

Properties

Core Properties

PropertyTypeDescription
codeRezoErrorCodeStringThe error code (e.g., 'ETIMEDOUT', 'REZ_HTTP_ERROR'). Enumerable.
messagestringHuman-readable error description. Derived from ERROR_INFO when code is set.
configRezoConfigThe request configuration that caused this error.
requestRezoHttpRequest \| undefinedThe request object, if available.
responseRezoResponse<T> \| undefinedThe response object, if one was received.
isRezoErrorbooleanAlways true. Used for duck-typing checks across module boundaries.

HTTP Properties

Available when the error was created from an HTTP response.

PropertyTypeDescription
statusnumber \| undefinedHTTP status code (e.g., 404, 500).
statusTextstring \| undefinedHTTP status text (e.g., "Not Found").

Network Properties

Available for network-level errors.

PropertyTypeDescription
errnonumber \| undefinedNumeric error code from ERROR_INFO.
causeError \| undefinedThe original underlying error.
syscallstring \| undefinedSystem call that failed (e.g., "connect").
hostnamestring \| undefinedTarget hostname that caused the error.
portnumber \| undefinedTarget port number.
addressstring \| undefinedTarget IP address.

suggestion

A recovery suggestion string from the ERROR_INFO database.

readonly suggestion: string
catch (err) {
  if (err instanceof RezoError) {
    console.log(err.suggestion);
    // "Verify the server is running and accessible. Check firewall rules..."
  }
}

Boolean Flags

All boolean flags are non-enumerable (accessible but hidden from console.log output). Use them for branching error handling logic.

FlagTypeDescription
isTimeoutbooleantrue for timeout errors (ETIMEDOUT, UND_ERR_CONNECT_TIMEOUT, UND_ERR_HEADERS_TIMEOUT, UND_ERR_REQUEST_TIMEOUT, ERR_TLS_HANDSHAKE_TIMEOUT, REZ_PROXY_TIMEOUT).
isAbortedbooleantrue for aborted requests (ABORT_ERR, UND_ERR_ABORTED).
isNetworkErrorbooleantrue for network-level failures (ECONNREFUSED, ECONNRESET, ENOTFOUND, EAI_AGAIN, EPIPE, EHOSTUNREACH, ENETUNREACH, UND_ERR_SOCKET).
isHttpErrorbooleantrue when code === 'REZ_HTTP_ERROR' (server returned a non-2xx status).
isProxyErrorbooleantrue for proxy-related errors (REZ_PROXY_CONNECTION_FAILED, REZ_PROXY_AUTHENTICATION_FAILED, etc.).
isSocksErrorbooleantrue for SOCKS proxy errors (REZ_SOCKS_CONNECTION_FAILED, REZ_SOCKS_AUTHENTICATION_FAILED, etc.).
isTlsErrorbooleantrue for TLS/SSL errors (EPROTO, CERT_HAS_EXPIRED, SELF_SIGNED_CERT_IN_CHAIN, etc.).
isRetryablebooleantrue for errors that may succeed on retry (timeouts, resets, DNS failures, rate limits, HTTP errors).

Example

try {
  await rezo.get('https://api.example.com/resource');
} catch (err) {
  if (!(err instanceof RezoError)) throw err;

  if (err.isTimeout) {
    console.log('Request timed out, retrying...');
  } else if (err.isHttpError && err.status === 429) {
    console.log('Rate limited, backing off...');
  } else if (err.isNetworkError) {
    console.log('Network issue:', err.code);
  } else if (err.isTlsError) {
    console.log('TLS problem:', err.message);
  } else if (err.isProxyError || err.isSocksError) {
    console.log('Proxy failed:', err.code);
  }

  if (err.isRetryable) {
    // Safe to retry this request
  }
}

Instance Methods

toJSON()

Serializes the error to a plain object. Only includes defined values.

toJSON(): Record<string, unknown>

Returns an object with: name, message, code, method, url, finalUrl, status, statusText, urls, cause.

toString()

Returns a formatted error string.

toString(): string
console.log(err.toString());
// "RezoError: Connection Refused [ECONNREFUSED]"

getFullDetails()

Returns a multi-line detailed error report.

getFullDetails(): string
console.log(err.getFullDetails());
// RezoError: Request failed with status code 404
// Code: REZ_HTTP_ERROR
// Method: GET
// URL: https://api.example.com/missing
// HTTP Status: 404 Not Found
//
// Suggestion: Check the status code and response body for more details about the error.

Static Methods

RezoError.isRezoError(error)

Type guard that checks if an unknown value is a RezoError instance. Works across module boundaries via duck-typing.

static isRezoError(error: unknown): error is RezoError

Example

try {
  await rezo.get('/api');
} catch (err) {
  if (RezoError.isRezoError(err)) {
    console.log(err.code); // TypeScript knows this is RezoError
  }
}

RezoError.fromError(error, config, request?, response?)

Wraps a native Error into a RezoError, preserving code, syscall, hostname, port, and address from the original.

static fromError<T = any>(error: Error, config: RezoConfig, request?: RezoHttpRequest, response?: RezoResponse<T>): RezoError<T>

Factory Methods

Each factory creates a RezoError with the appropriate error code pre-set.

static createHttpError<T>(statusCode: number, config: RezoConfig, request?: RezoHttpRequest, response?: RezoResponse<T>): RezoError<T>
static createNetworkError<T>(message: string, code: RezoErrorCodeString, config: RezoConfig, request?: RezoHttpRequest): RezoError<T>
static createTimeoutError<T>(message: string, config: RezoConfig, request?: RezoHttpRequest): RezoError<T>
static createAbortError<T>(message: string, config: RezoConfig, request?: RezoHttpRequest): RezoError<T>
static createParsingError<T>(message: string, config: RezoConfig, request?: RezoHttpRequest): RezoError<T>
static createEnvironmentError<T>(message: string, config: RezoConfig): RezoError<T>
static createDecompressionError<T>(message: string, config: RezoConfig, request?: RezoHttpRequest, response?: RezoResponse<T>): RezoError<T>
static createDownloadError<T>(message: string, config: RezoConfig, request?: RezoHttpRequest, response?: RezoResponse<T>): RezoError<T>
static createUploadError<T>(message: string, config: RezoConfig, request?: RezoHttpRequest, response?: RezoResponse<T>): RezoError<T>
static createStreamError<T>(message: string, config: RezoConfig, request?: RezoHttpRequest, response?: RezoResponse<T>): RezoError<T>
static createRedirectError<T>(message: string, config: RezoConfig, request?: RezoHttpRequest, response?: RezoResponse<T>): RezoError<T>
static createProxyError<T>(code: RezoErrorCodeString, config: RezoConfig, request?: RezoHttpRequest): RezoError<T>
static createSocksError<T>(code: RezoErrorCodeString, config: RezoConfig, request?: RezoHttpRequest): RezoError<T>
static createTlsError<T>(code: RezoErrorCodeString, config: RezoConfig, request?: RezoHttpRequest): RezoError<T>
static createRateLimitError<T>(config: RezoConfig, request?: RezoHttpRequest, response?: RezoResponse<T>): RezoError<T>

RezoErrorCode Enum

The RezoErrorCode enum provides named constants for all error codes. Use it for readable comparisons.

Network / OS

ConstantValueDescription
CONNECTION_REFUSED'ECONNREFUSED'Server refused the TCP connection.
CONNECTION_RESET'ECONNRESET'Connection forcibly closed by peer.
CONNECTION_ABORTED'ECONNABORTED'Connection aborted locally.
CONNECTION_TIMEOUT'ETIMEDOUT'TCP connection timed out.
SOCKET_TIMEOUT'ESOCKETTIMEDOUT'Socket timed out waiting for data.
DNS_LOOKUP_FAILED'ENOTFOUND'DNS lookup failed.
DNS_TEMPORARY_FAILURE'EAI_AGAIN'Temporary DNS failure.
HOST_UNREACHABLE'EHOSTUNREACH'No route to host.
NETWORK_UNREACHABLE'ENETUNREACH'Network unreachable.
BROKEN_PIPE'EPIPE'Connection closed while writing.

HTTP

ConstantValueDescription
HTTP_ERROR'REZ_HTTP_ERROR'Non-2xx HTTP response.
REDIRECT_DENIED'REZ_REDIRECT_DENIED'Redirect blocked by config.
MAX_REDIRECTS'REZ_MAX_REDIRECTS_EXCEEDED'Too many redirects.
REDIRECT_CYCLE'REZ_REDIRECT_CYCLE_DETECTED'Circular redirect detected.
RATE_LIMITED'REZ_RATE_LIMITED'429 Too Many Requests.

Streams / Transfer

ConstantValueDescription
DOWNLOAD_FAILED'REZ_DOWNLOAD_FAILED'Download failed during transfer.
UPLOAD_FAILED'REZ_UPLOAD_FAILED'Upload failed during transfer.
STREAM_ERROR'REZ_STREAM_ERROR'Error processing response stream.
BODY_TOO_LARGE'REZ_BODY_TOO_LARGE'Request body exceeds limit.
RESPONSE_TOO_LARGE'REZ_RESPONSE_TOO_LARGE'Response body exceeds limit.

Parsing / Validation

ConstantValueDescription
INVALID_JSON'REZ_INVALID_JSON'Failed to parse JSON response.
INVALID_URL'ERR_INVALID_URL'Invalid URL syntax.
INVALID_PROTOCOL'ERR_INVALID_PROTOCOL'Unsupported URL protocol.

Proxy

ConstantValueDescription
PROXY_CONNECTION_FAILED'REZ_PROXY_CONNECTION_FAILED'Cannot connect to proxy.
PROXY_AUTH_FAILED'REZ_PROXY_AUTHENTICATION_FAILED'Proxy auth rejected.
PROXY_TARGET_UNREACHABLE'REZ_PROXY_TARGET_UNREACHABLE'Proxy cannot reach target.
PROXY_TIMEOUT'REZ_PROXY_TIMEOUT'Proxy connection timed out.
NO_PROXY_AVAILABLE'REZ_NO_PROXY_AVAILABLE'All proxies exhausted.

SOCKS

ConstantValueDescription
SOCKS_CONNECTION_FAILED'REZ_SOCKS_CONNECTION_FAILED'SOCKS proxy unreachable.
SOCKS_AUTH_FAILED'REZ_SOCKS_AUTHENTICATION_FAILED'SOCKS auth rejected.
SOCKS_PROTOCOL_ERROR'REZ_SOCKS_PROTOCOL_ERROR'Invalid SOCKS response.

TLS / SSL

ConstantValueDescription
TLS_HANDSHAKE_TIMEOUT'ERR_TLS_HANDSHAKE_TIMEOUT'TLS handshake timed out.
TLS_PROTOCOL_ERROR'EPROTO'Protocol error during TLS.
CERTIFICATE_EXPIRED'CERT_HAS_EXPIRED'Server certificate expired.
CERTIFICATE_SELF_SIGNED'SELF_SIGNED_CERT_IN_CHAIN'Self-signed certificate.
CERTIFICATE_HOSTNAME_MISMATCH'ERR_TLS_CERT_ALTNAME_INVALID'Hostname does not match cert.

Example

import { RezoErrorCode } from 'rezo';

try {
  await rezo.get('/api');
} catch (err) {
  if (err.code === RezoErrorCode.CONNECTION_REFUSED) {
    console.log('Server is down');
  } else if (err.code === RezoErrorCode.RATE_LIMITED) {
    console.log('Slow down');
  }
}