java.lang.Object
io.jooby.trpc.TrpcErrorHandler
- All Implemented Interfaces:
io.jooby.ErrorHandler
A specialized error handler that formats exceptions into tRPC-compliant JSON responses.
This handler strictly listens for requests where the path begins with /trpc/. When an
exception occurs during a tRPC procedure, this handler ensures the response matches the exact
JSON envelope expected by the frontend @trpc/client, preventing the client from crashing
due to unexpected HTML or plain-text error pages.
Custom Exception Mapping:
By default, this handler translates standard Jooby StatusCodes into their
corresponding TrpcErrorCode. However, you can register a custom Map<Class<?>,
TrpcErrorCode> in the Jooby registry to map your own domain-specific exceptions directly to tRPC
codes.
If the thrown exception is already a TrpcException, it is rendered directly without
modification.
-
Constructor Details
-
TrpcErrorHandler
public TrpcErrorHandler()
-
-
Method Details
-
apply
public void apply(@NonNull io.jooby.Context ctx, @NonNull Throwable cause, @NonNull io.jooby.StatusCode code) Applies the tRPC error formatting if the request is a tRPC call.- Specified by:
applyin interfaceio.jooby.ErrorHandler- Parameters:
ctx- The current routing context.cause- The exception that was thrown during the request lifecycle.code- The default HTTP status code resolved by Jooby.
-