tryError Documentation

Interface: ExternalError\<T\>
Interface

Defined in: [factories.ts:306](https://github.com/oconnorjohnson/try-error/blob/e3ae0308069a4fba073f4543d527ad76373db795/src/factories.ts#L306) Base type for errors from external services (APIs, third-party services, etc.) Provides consistent fields for external service errors across different integrations.

tryError API Documentation v0.0.1-alpha.1


tryError API Documentation / ExternalError

Interface: ExternalError<T>

Defined in: factories.ts:306

Base type for errors from external services (APIs, third-party services, etc.)

Provides consistent fields for external service errors across different integrations.

Example

interface ApiError
  extends ExternalError<"NetworkError" | "AuthError" | "RateLimited"> {
  readonly endpoint: string;
}

const error: ApiError = {
  ...createError({ type: "RateLimited", message: "Rate limit exceeded" }),
  provider: "stripe",
  externalId: "req_123",
  statusCode: 429,
  endpoint: "/v1/charges",
};

Extends

Type Parameters

T

T extends 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


externalId?

readonly optional externalId: string;

Defined in: factories.ts:315

External reference ID (request ID, transaction ID, etc.)


message

readonly message: string;

Defined in: types.ts:25

Human-readable error message

Inherited from

TryError.message


provider

readonly provider: string;

Defined in: factories.ts:310

The name of the external service/provider


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


statusCode?

readonly optional statusCode: number;

Defined in: factories.ts:320

HTTP status code or equivalent error code


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