Package io.jooby.trpc

Enum Class TrpcErrorCode

java.lang.Object
java.lang.Enum<TrpcErrorCode>
io.jooby.trpc.TrpcErrorCode
All Implemented Interfaces:
Serializable, Comparable<TrpcErrorCode>, Constable

public enum TrpcErrorCode extends Enum<TrpcErrorCode>
Maps standard Jooby HTTP status codes to official tRPC error codes.

The tRPC specification dictates that failed requests must return specific JSON-RPC style integer codes (e.g., -32600) in the JSON response payload, alongside the standard HTTP status codes. This enumeration defines the canonical mapping between Jooby's StatusCode and the expected tRPC error shape.

When an exception is thrown within a tRPC route, Jooby uses this mapping to format the error response so the frontend @trpc/client can correctly parse and reconstruct the TRPCClientError.

  • Enum Constant Details

    • BAD_REQUEST

      public static final TrpcErrorCode BAD_REQUEST
      Invalid routing or parameters. Mapped to HTTP 400.
    • PARSE_ERROR

      public static final TrpcErrorCode PARSE_ERROR
      The server received invalid JSON. Mapped to HTTP 400.
    • INTERNAL_SERVER_ERROR

      public static final TrpcErrorCode INTERNAL_SERVER_ERROR
      Internal server error. Mapped to HTTP 500.
    • UNAUTHORIZED

      public static final TrpcErrorCode UNAUTHORIZED
      Missing or invalid authentication. Mapped to HTTP 401.
    • FORBIDDEN

      public static final TrpcErrorCode FORBIDDEN
      Authenticated user lacks required permissions. Mapped to HTTP 403.
    • NOT_FOUND

      public static final TrpcErrorCode NOT_FOUND
      The requested resource or tRPC procedure was not found. Mapped to HTTP 404.
    • METHOD_NOT_SUPPORTED

      public static final TrpcErrorCode METHOD_NOT_SUPPORTED
      The HTTP method used is not supported by the procedure (e.g., GET on a mutation). Mapped to HTTP 405.
    • TIMEOUT

      public static final TrpcErrorCode TIMEOUT
      The request took too long to process. Mapped to HTTP 408.
    • CONFLICT

      public static final TrpcErrorCode CONFLICT
      State conflict, such as a duplicate database entry. Mapped to HTTP 409.
    • PRECONDITION_FAILED

      public static final TrpcErrorCode PRECONDITION_FAILED
      The client's preconditions were not met. Mapped to HTTP 412.
    • PAYLOAD_TOO_LARGE

      public static final TrpcErrorCode PAYLOAD_TOO_LARGE
      The incoming request payload exceeds the allowed limits. Mapped to HTTP 413.
    • UNPROCESSABLE_CONTENT

      public static final TrpcErrorCode UNPROCESSABLE_CONTENT
      The payload format is valid, but the content is semantically incorrect. Mapped to HTTP 422.
    • TOO_MANY_REQUESTS

      public static final TrpcErrorCode TOO_MANY_REQUESTS
      Rate limiting applied. Mapped to HTTP 429.
    • CLIENT_CLOSED_REQUEST

      public static final TrpcErrorCode CLIENT_CLOSED_REQUEST
      The client disconnected before the server could respond. Mapped to HTTP 499.
  • Method Details

    • values

      public static TrpcErrorCode[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static TrpcErrorCode valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • getRpcCode

      public int getRpcCode()
      Retrieves the JSON-RPC style integer code.
      Returns:
      The tRPC integer code (e.g., -32600).
    • getStatusCode

      public io.jooby.StatusCode getStatusCode()
      Retrieves the corresponding HTTP status code.
      Returns:
      The Jooby StatusCode.
    • of

      public static TrpcErrorCode of(io.jooby.StatusCode status)
      Resolves the closest tRPC error code for a given Jooby HTTP status code.

      If an exact match is not found for the provided HTTP status, this method falls back to INTERNAL_SERVER_ERROR.

      Parameters:
      status - The Jooby HTTP status code.
      Returns:
      The corresponding TrpcErrorCode, or INTERNAL_SERVER_ERROR if no match exists.