tryError Documentation
Function: wrapWithContext()
Function
```ts function wrapWithContext<E>(error, additionalContext): E; ``` Defined in: [factories.ts:424](https://github.com/oconnorjohnson/try-error/blob/e3ae0308069a4fba073f4543d527ad76373db795/src/factories.ts#L424) Wrap an error with additional context while preserving the original type Useful for adding context to an error without changing its type, such as adding request IDs or user context.
tryError API Documentation v0.0.1-alpha.1
tryError API Documentation / wrapWithContext
Function: wrapWithContext()
function wrapWithContext<E>(error, additionalContext): E;
Defined in: factories.ts:424
Wrap an error with additional context while preserving the original type
Useful for adding context to an error without changing its type, such as adding request IDs or user context.
Type Parameters
E
E
extends TryError
<string
>
Parameters
error
E
The original error
additionalContext
Record
<string
, unknown
>
Additional context to merge
Returns
E
The same error with additional context
Example
const error = createError({
type: "ValidationError",
message: "Invalid input",
});
const contextualError = wrapWithContext(error, {
requestId: "req_123",
userId: "user_456",
});