node-comfortv2.0.0

nc.errors

The errors node-comfort throws. They all extend NodeComfortError (itself a regular Error) and carry a stable code, so you can branch on the kind of failure without parsing messages.

const { errors } = require("@ix-xs/node-comfort");
import { default } from "@ix-xs/node-comfort/errors";
try {
  await nc.http.get("https://api.example.com/users/42");
} catch (error) {
  if (error instanceof nc.errors.HttpError && error.status === 404) return null;
  throw error;
}
GuideExplanations and examples for nc.errors.
Read the guide →

Functions

nc.errors.NodeComfortErrorproperty

NodeComfortError: typeof NodeComfortError

Base class of every node-comfort error. name is the class name and code a stable identifier.

nc.errors.AssertionErrorproperty

AssertionError: typeof AssertionError

Thrown by nc.assert() and nc.assertType().

nc.errors.TimeoutErrorproperty

TimeoutError: typeof TimeoutError

Thrown when something takes too long: func.timeout, async.poll, HTTP requests, emitter.waitFor...

nc.errors.AbortErrorproperty

AbortError: typeof AbortError

Thrown when an operation is cancelled with an AbortSignal. Its name is "AbortError", like native abort errors, so existing checks keep working.

nc.errors.ValidationErrorproperty

ValidationError: typeof ValidationError

Thrown when data doesn't match a schema or when environment variables are invalid. issues lists every problem, not just the first one.

nc.errors.HttpErrorproperty

HttpError: typeof HttpError

Thrown by nc.http when the response status isn't 2xx (unless you pass throwHttpErrors: false), and for network failures (status 0).

nc.errors.JWTErrorproperty

JWTError: typeof JWTError

Thrown by nc.crypto.verifyJWT(). The code tells you why: ERR_JWT_MALFORMED, ERR_JWT_ALGORITHM, ERR_JWT_SIGNATURE, ERR_JWT_EXPIRED, ERR_JWT_NOT_BEFORE or ERR_JWT_CLAIM.

nc.errors.ProcessErrorproperty

ProcessError: typeof ProcessError

Thrown by nc.sys.run() and nc.sys.exec() when a command fails, is killed or times out. Its output is kept on the error.

nc.errors.SQLiteErrorproperty

SQLiteError: typeof SQLiteError

Thrown by nc.SQLite when a statement fails. Check sqliteCode to handle specific cases like a duplicate value.

Types

Import any of them in TypeScript with import type { NodeComfortErrorOptions } from "@ix-xs/node-comfort", or in JavaScript with import("@ix-xs/node-comfort").NodeComfortErrorOptions.

NodeComfortErrorOptions

Options shared by every error constructor.

PropertyTypeDescription
codeoptionalstringMachine-readable code, like "ETIMEDOUT".
causeoptionalunknownThe error that caused this one, kept as error.cause.

ValidationIssue

One problem found while validating data.

PropertyTypeDescription
path(string | number)[]Where the problem is, like ["user", "emails", 0]. Empty for the root value.
codestringWhat went wrong: "invalid_type", "too_small", "invalid_string", "custom"...
messagestringA message you can show to users.
expectedoptionalstringThe expected type, for type errors.
receivedoptionalstringThe received type, for type errors.
node-comfort v2.0.0View the source