The global errorFormatter is probably what you want, check instanceof your own error class, then turn it into the “shape” you want including error code
But also this is RPC, thinking too much in http codes is the wrong mindset, passing back a code with similar meanings is fine, you can even return a “valid” response with an error key if you like, just throwing is the more standard approach
I assume you've read the docs, but you can set your error codes in tRPCError, might be able to set that within the errorFormatter too, but definitely can handle errors and do some bespoke logging for your infra needs
Whenever an error occurs in a procedure, tRPC responds to the client with an object that includes an "error" property. This property contains all the information that you need to handle the error in the client.