⬆️ Upgrade sentry and improve its reliability
This commit is contained in:
@@ -2,11 +2,18 @@ import { initTRPC } from '@trpc/server'
|
||||
import { OpenApiMeta } from 'trpc-openapi'
|
||||
import superjson from 'superjson'
|
||||
import { Context } from './context'
|
||||
import * as Sentry from '@sentry/nextjs'
|
||||
|
||||
const t = initTRPC.context<Context>().meta<OpenApiMeta>().create({
|
||||
transformer: superjson,
|
||||
})
|
||||
|
||||
const sentryMiddleware = t.middleware(
|
||||
Sentry.Handlers.trpcMiddleware({
|
||||
attachRpcInput: true,
|
||||
})
|
||||
)
|
||||
|
||||
const injectUser = t.middleware(({ next, ctx }) => {
|
||||
return next({
|
||||
ctx: {
|
||||
@@ -15,8 +22,10 @@ const injectUser = t.middleware(({ next, ctx }) => {
|
||||
})
|
||||
})
|
||||
|
||||
const finalMiddleware = sentryMiddleware.unstable_pipe(injectUser)
|
||||
|
||||
export const middleware = t.middleware
|
||||
|
||||
export const router = t.router
|
||||
|
||||
export const publicProcedure = t.procedure.use(injectUser)
|
||||
export const publicProcedure = t.procedure.use(finalMiddleware)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { appRouter } from '@/helpers/server/routers/appRouterV1'
|
||||
import { captureException } from '@sentry/nextjs'
|
||||
import * as Sentry from '@sentry/nextjs'
|
||||
import { createOpenApiNextHandler } from 'trpc-openapi'
|
||||
import cors from 'nextjs-cors'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
@@ -13,7 +13,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
createContext,
|
||||
onError({ error }) {
|
||||
if (error.code === 'INTERNAL_SERVER_ERROR') {
|
||||
captureException(error)
|
||||
Sentry.captureException(error)
|
||||
console.error('Something went wrong', error)
|
||||
}
|
||||
},
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { appRouter } from '@/helpers/server/routers/appRouterV2'
|
||||
import { captureException } from '@sentry/nextjs'
|
||||
import * as Sentry from '@sentry/nextjs'
|
||||
import { createOpenApiNextHandler } from 'trpc-openapi'
|
||||
import cors from 'nextjs-cors'
|
||||
import { NextApiRequest, NextApiResponse } from 'next'
|
||||
@@ -13,7 +13,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
createContext,
|
||||
onError({ error }) {
|
||||
if (error.code === 'INTERNAL_SERVER_ERROR') {
|
||||
captureException(error)
|
||||
Sentry.captureException(error)
|
||||
console.error('Something went wrong', error)
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user