Skip to content

Commit 5c06bd2

Browse files
authored
fix(core): Update trpc middleware types (#13859)
1 parent 0b739c5 commit 5c06bd2

File tree

3 files changed

+12
-10
lines changed
  • dev-packages/e2e-tests/test-applications
  • packages/core/src

3 files changed

+12
-10
lines changed

dev-packages/e2e-tests/test-applications/nextjs-t3/src/server/api/trpc.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ export const createCallerFactory = t.createCallerFactory;
7070
*/
7171
export const createTRPCRouter = t.router;
7272

73-
const sentryMiddleware = Sentry.trpcMiddleware({
74-
attachRpcInput: true,
75-
});
76-
77-
export const publicProcedure = t.procedure.use(async opts => sentryMiddleware(opts));
73+
export const publicProcedure = t.procedure.use(
74+
Sentry.trpcMiddleware({
75+
attachRpcInput: true,
76+
}),
77+
);

dev-packages/e2e-tests/test-applications/node-express/src/app.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ Sentry.addEventProcessor(event => {
105105

106106
export const t = initTRPC.context<Context>().create();
107107

108-
const sentryMiddleware = Sentry.trpcMiddleware({ attachRpcInput: true });
109-
110-
const procedure = t.procedure.use(async opts => sentryMiddleware(opts));
108+
const procedure = t.procedure.use(Sentry.trpcMiddleware({ attachRpcInput: true }));
111109

112110
export const appRouter = t.router({
113111
getSomething: procedure.input(z.string()).query(opts => {

packages/core/src/trpc.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ function captureIfError(nextResult: unknown): void {
3333
}
3434
}
3535

36+
type SentryTrpcMiddleware<T> = T extends Promise<unknown> ? T : Promise<T>;
37+
3638
/**
3739
* Sentry tRPC middleware that captures errors and creates spans for tRPC procedures.
3840
*/
3941
export function trpcMiddleware(options: SentryTrpcMiddlewareOptions = {}) {
40-
return async function <T>(opts: SentryTrpcMiddlewareArguments<T>): Promise<T> {
42+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
43+
// @ts-ignore
44+
return async function <T>(opts: SentryTrpcMiddlewareArguments<T>): SentryTrpcMiddleware<T> {
4145
const { path, type, next, rawInput, getRawInput } = opts;
4246

4347
const client = getClient();
@@ -85,6 +89,6 @@ export function trpcMiddleware(options: SentryTrpcMiddlewareOptions = {}) {
8589
throw e;
8690
}
8791
},
88-
);
92+
) as SentryTrpcMiddleware<T>;
8993
};
9094
}

0 commit comments

Comments
 (0)