Skip to content

Rethrow Handler Plugin

The RethrowHandlerPlugin allows you to catch and rethrow specific errors that occur during request handling. This is particularly useful when your framework has its own error handling mechanism (e.g., global exception filters in NestJS, error middleware in Express) and you want certain errors to be processed by that mechanism instead of being handled by the oRPC error handling flow.

Usage

ts
import {
  
experimental_RethrowHandlerPlugin
as
RethrowHandlerPlugin
,
} from '@orpc/server/plugins' const
handler
= new
RPCHandler
(
router
, {
plugins
: [
new
RethrowHandlerPlugin
({
// Decide which errors should be rethrown.
filter
: (
error
) => {
// Example: Rethrow all non-ORPCError errors // This allows unhandled exceptions to bubble up to your framework return !(
error
instanceof
ORPCError
)
}, }), ], })

INFO

The handler can be any supported oRPC handler, such as RPCHandler, OpenAPIHandler, or another custom handler.

Released under the MIT License.