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>
) | Parameter | Type | Description |
|---|---|---|
message | string | Human-readable error message. Overridden by ERROR_INFO lookup if code is provided. |
config | RezoConfig | The request configuration that produced this error. |
code | RezoErrorCodeString | Error code string (e.g., 'ECONNREFUSED', 'REZ_HTTP_ERROR'). |
request | RezoHttpRequest | The underlying request object, if available. |
response | RezoResponse<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
| Property | Type | Description |
|---|---|---|
code | RezoErrorCodeString | The error code (e.g., 'ETIMEDOUT', 'REZ_HTTP_ERROR'). Enumerable. |
message | string | Human-readable error description. Derived from ERROR_INFO when code is set. |
config | RezoConfig | The request configuration that caused this error. |
request | RezoHttpRequest \| undefined | The request object, if available. |
response | RezoResponse<T> \| undefined | The response object, if one was received. |
isRezoError | boolean | Always true. Used for duck-typing checks across module boundaries. |
HTTP Properties
Available when the error was created from an HTTP response.
| Property | Type | Description |
|---|---|---|
status | number \| undefined | HTTP status code (e.g., 404, 500). |
statusText | string \| undefined | HTTP status text (e.g., "Not Found"). |
Network Properties
Available for network-level errors.
| Property | Type | Description |
|---|---|---|
errno | number \| undefined | Numeric error code from ERROR_INFO. |
cause | Error \| undefined | The original underlying error. |
syscall | string \| undefined | System call that failed (e.g., "connect"). |
hostname | string \| undefined | Target hostname that caused the error. |
port | number \| undefined | Target port number. |
address | string \| undefined | Target 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.
| Flag | Type | Description |
|---|---|---|
isTimeout | boolean | true for timeout errors (ETIMEDOUT, UND_ERR_CONNECT_TIMEOUT, UND_ERR_HEADERS_TIMEOUT, UND_ERR_REQUEST_TIMEOUT, ERR_TLS_HANDSHAKE_TIMEOUT, REZ_PROXY_TIMEOUT). |
isAborted | boolean | true for aborted requests (ABORT_ERR, UND_ERR_ABORTED). |
isNetworkError | boolean | true for network-level failures (ECONNREFUSED, ECONNRESET, ENOTFOUND, EAI_AGAIN, EPIPE, EHOSTUNREACH, ENETUNREACH, UND_ERR_SOCKET). |
isHttpError | boolean | true when code === 'REZ_HTTP_ERROR' (server returned a non-2xx status). |
isProxyError | boolean | true for proxy-related errors (REZ_PROXY_CONNECTION_FAILED, REZ_PROXY_AUTHENTICATION_FAILED, etc.). |
isSocksError | boolean | true for SOCKS proxy errors (REZ_SOCKS_CONNECTION_FAILED, REZ_SOCKS_AUTHENTICATION_FAILED, etc.). |
isTlsError | boolean | true for TLS/SSL errors (EPROTO, CERT_HAS_EXPIRED, SELF_SIGNED_CERT_IN_CHAIN, etc.). |
isRetryable | boolean | true 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
| Constant | Value | Description |
|---|---|---|
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
| Constant | Value | Description |
|---|---|---|
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
| Constant | Value | Description |
|---|---|---|
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
| Constant | Value | Description |
|---|---|---|
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
| Constant | Value | Description |
|---|---|---|
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
| Constant | Value | Description |
|---|---|---|
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
| Constant | Value | Description |
|---|---|---|
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');
}
}