kgni
kgni
TtRPC
Created by kgni on 7/11/2024 in #❓-help
default TRPCError, try/catch & dealing with DatabaseErrors
Hi there! I'm quite new to tRPC and was hoping that someone could help me out with some general questions related to errors and errorhandling. Thanks in advance! 1. Default TRPCError It seems like that the fallback / default error that is thrown from the trpc server is a TRPCError with code INTERNAL_SERVER_ERROR - is this correct? 2. try/catch If the above is true, I guess in some cases I don't even need to use a try...catch block? Let's say I'm not checking any specific database errors or anything - then I could leave out try...catch all together - or is it considered a best practice to always just use try...catch for consistency when dealing with async operations, and then throw an INTERNAL_SERVER_ERROR manually? 3. Handling database errors To combat the above try...catch consistency dillema, I'm thinking about implementing a general errorHandler that handles various database errors thrown by my postgres db. This handler can then throw specific TRPCErrors depending on the the postgres errors. Additionally, I could extend the TRPCError class to include a translation string for my frontend. Does this approach sound reasonable?
2 replies
TtRPC
Created by kgni on 5/6/2024 in #❓-help
tRPC context, NeonDB & WebSockets
Hi there! I'm currently working on a serverless app with the following tech stack: Cloudflare Workers, Hono, tRPC, DrizzleORM & NeonDB. I'm trying to create 2 Neon client instances (using DrizzleORM) on my tRPC server that is running on Cloudflare Workers. 1 for HTTP 1 for WebSockets (this is used for transactions) I'm a bit confused as to when the WebSocket connection will open. Currently I'm creating both db client instances in the tRPC context (using the Hono tRPC adapter) - so will a WebSocket connection open every single time a procedure runs, or only when I'm actually accessing and using the WebSocket db client in my procedure? I made this gist with the files I have currently
15 replies