Package io.jooby.trpc

Class TrpcErrorHandler

java.lang.Object
io.jooby.trpc.TrpcErrorHandler
All Implemented Interfaces:
io.jooby.ErrorHandler

public class TrpcErrorHandler extends Object implements 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 Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    apply(io.jooby.Context ctx, Throwable cause, io.jooby.StatusCode code)
    Applies the tRPC error formatting if the request is a tRPC call.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.jooby.ErrorHandler

    then
  • Constructor Details

    • TrpcErrorHandler

      public TrpcErrorHandler()
  • Method Details

    • apply

      public void apply(io.jooby.Context ctx, Throwable cause, io.jooby.StatusCode code)
      Applies the tRPC error formatting if the request is a tRPC call.
      Specified by:
      apply in interface io.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.