tryError Documentation

Interface: EntityError\<T, EntityType\>
Interface

Defined in: [factories.ts:240](https://github.com/oconnorjohnson/try-error/blob/e3ae0308069a4fba073f4543d527ad76373db795/src/factories.ts#L240) Base type for errors related to specific entities (users, orders, products, etc.) Provides consistent fields for entity-related errors across different domains.

tryError API Documentation v0.0.1-alpha.1


tryError API Documentation / EntityError

Interface: EntityError<T, EntityType>

Defined in: factories.ts:240

Base type for errors related to specific entities (users, orders, products, etc.)

Provides consistent fields for entity-related errors across different domains.

Example

interface UserError
  extends EntityError<"UserNotFound" | "UserSuspended", "user"> {
  readonly accountStatus?: string;
}

const error: UserError = {
  ...createError({ type: "UserNotFound", message: "User not found" }),
  entityId: "user_123",
  entityType: "user",
  accountStatus: "active",
};

Extends

Type Parameters

T

T extends string

EntityType

EntityType extends string = string

Properties

cause?

readonly optional cause: unknown;

Defined in: types.ts:50

The original error or thrown value that caused this error

Inherited from

TryError.cause


context?

readonly optional context: Record<string, unknown>;

Defined in: types.ts:45

Additional context data for debugging

Inherited from

TryError.context


entityId

readonly entityId: string;

Defined in: factories.ts:247

The ID of the entity that caused the error


entityType

readonly entityType: EntityType;

Defined in: factories.ts:252

The type of entity (user, order, product, etc.)


message

readonly message: string;

Defined in: types.ts:25

Human-readable error message

Inherited from

TryError.message


source

readonly source: string;

Defined in: types.ts:35

Source location where the error occurred (file:line:column)

Inherited from

TryError.source


stack?

readonly optional stack: string;

Defined in: types.ts:30

Stack trace if available (may be stripped in production)

Inherited from

TryError.stack


timestamp

readonly timestamp: number;

Defined in: types.ts:40

Timestamp when the error was created

Inherited from

TryError.timestamp


type

readonly type: T;

Defined in: types.ts:20

The type of error - used for discriminated unions

Inherited from

TryError.type