@@ -50,6 +50,23 @@ export const createTrpcContext = cache(async (): Promise<TrpcContext> => {
5050 } ;
5151} ) ;
5252
53+ // Client errors that shouldn't be logged at error level
54+ export const CLIENT_ERROR_CODES = new Set ( [
55+ 'PARSE_ERROR' ,
56+ 'BAD_REQUEST' ,
57+ 'UNAUTHORIZED' ,
58+ 'NOT_FOUND' ,
59+ 'FORBIDDEN' ,
60+ 'METHOD_NOT_SUPPORTED' ,
61+ 'TIMEOUT' ,
62+ 'CONFLICT' ,
63+ 'PRECONDITION_FAILED' ,
64+ 'PAYLOAD_TOO_LARGE' ,
65+ 'UNPROCESSABLE_CONTENT' ,
66+ 'TOO_MANY_REQUESTS' ,
67+ 'CLIENT_CLOSED_REQUEST' ,
68+ ] ) ;
69+
5370// Avoid exporting the entire t-object
5471// since it's not very descriptive.
5572// For instance, the use of a t variable
@@ -61,20 +78,7 @@ const t = initTRPC.context<TrpcContext>().create({
6178 transformer : superjson ,
6279 errorFormatter : ( { shape, error, path} ) => {
6380 // Only capture server errors to Sentry, not client errors (crawlers, bad requests, etc.)
64- const isClientError =
65- error . code === 'PARSE_ERROR' ||
66- error . code === 'BAD_REQUEST' ||
67- error . code === 'UNAUTHORIZED' ||
68- error . code === 'NOT_FOUND' ||
69- error . code === 'FORBIDDEN' ||
70- error . code === 'METHOD_NOT_SUPPORTED' ||
71- error . code === 'TIMEOUT' ||
72- error . code === 'CONFLICT' ||
73- error . code === 'PRECONDITION_FAILED' ||
74- error . code === 'PAYLOAD_TOO_LARGE' ||
75- error . code === 'UNPROCESSABLE_CONTENT' ||
76- error . code === 'TOO_MANY_REQUESTS' ||
77- error . code === 'CLIENT_CLOSED_REQUEST' ;
81+ const isClientError = CLIENT_ERROR_CODES . has ( error . code ) ;
7882
7983 if ( ! isClientError ) {
8084 Sentry . captureException ( error . cause ?? error , {
0 commit comments