docs(core-shared): correct defineErrorMiddleware jsdoc to match implementation

Code-quality reviewer flagged a stale 'try/catch' phrase in the jsdoc
that didn't match the actual result.ok inspection pattern. Updated
description to accurately describe how tRPC v11 middleware sees errors
(returned result, not thrown exception) and how the middleware
discriminates and rethrows.

Pure docstring change — no behavioral or signature impact.
This commit is contained in:
2026-05-06 11:54:51 +02:00
parent e25b1f7a1c
commit aac37fd9af

View File

@@ -7,11 +7,16 @@ type ErrorCtor = new (...args: never[]) => Error;
/**
* Build a tRPC middleware that translates domain errors to TRPCError.
*
* Each tuple pairs a constructor with a TRPC error code. The middleware
* runs the procedure body inside a try/catch; on `instanceof Ctor`,
* it throws a TRPCError with the configured code and the original error
* preserved as `.cause`. Unmapped errors propagate untouched (tRPC's
* default INTERNAL_SERVER_ERROR handling applies).
* Each tuple pairs a constructor with a TRPC error code. tRPC v11
* middleware sees procedure throws as a returned `result` (not an
* exception): `next()` resolves to `{ ok: false, error: TRPCError }`
* where `error.cause` is the original domain error wrapped by
* `getTRPCErrorFromUnknown`. The middleware checks `result.ok`,
* matches `result.error.cause` against each `instanceof Ctor`, and
* on a hit throws a fresh TRPCError with the configured code and the
* original error preserved as `.cause`. Unmapped errors fall through
* unchanged — tRPC's default INTERNAL_SERVER_ERROR wrapping applies
* with the original error still reachable via `.cause`.
*
* Owned by features: each feature passes its own constructors in.
* core-shared never enumerates feature-specific error classes.