method BaseError.prototype.withContext
BaseError.prototype.withContext(context?: Record<string, unknown>): this

Add contextual information to this error. Useful for adding runtime context like request IDs, user IDs, etc.

Examples

Example 1

const error = new UnauthorizedError({ reason: "Invalid token" })
  .withContext({ userId: "123", requestId: "req-456" });

Parameters

optional
context: Record<string, unknown>

Key-value pairs to add to the error context

Return Type

this

This error instance for chaining

Usage

import { BaseError } from "result/mod.ts";