Hik
Hik
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Hik on 7/12/2023 in #questions
Sentry Integration
you make an errorFormatter and then you can use that shape in the onError handler whereever you deploy your app:
// packages/api/src/trpc.ts
const t = initTRPC.context<...>().create({
transformer: ...,
errorFormatter: ...,
})

// apps/nextjs/pages/api/trpc/[trpc].ts
export default trpcNext.createNextApiHandler({
onError({ error, shape }) {
if (error.code === 'INTERNAL_SERVER_ERROR') {
shape; // whatever shape you return from the formatter

// send to bug reporting
console.error('Something went wrong', error);
}
},
});
// packages/api/src/trpc.ts
const t = initTRPC.context<...>().create({
transformer: ...,
errorFormatter: ...,
})

// apps/nextjs/pages/api/trpc/[trpc].ts
export default trpcNext.createNextApiHandler({
onError({ error, shape }) {
if (error.code === 'INTERNAL_SERVER_ERROR') {
shape; // whatever shape you return from the formatter

// send to bug reporting
console.error('Something went wrong', error);
}
},
});
alternatively, if you wanna go down the middleware route:
const forwardErrorMiddleware = middleware(async (opts) => {
const result = await opts.next();
if (!result.ok) {
// handle error and send somewhere
// console.log("Error occured in procedure", opts.path);
}
return result;
});

export const publicProcedure = t.procedure.use(forwardErrorMiddleware);
const forwardErrorMiddleware = middleware(async (opts) => {
const result = await opts.next();
if (!result.ok) {
// handle error and send somewhere
// console.log("Error occured in procedure", opts.path);
}
return result;
});

export const publicProcedure = t.procedure.use(forwardErrorMiddleware);
3 replies
TTCTheo's Typesafe Cult
Created by Hik on 7/12/2023 in #questions
Sentry Integration
answer by @marminge moved from ct3a-meta to questions
3 replies