48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
/* eslint-disable canonical/filename-match-regex */
|
|
import { createContext } from '@/server/context';
|
|
import { appRouter } from '@/server/routers/_app';
|
|
import { captureException, withScope } from '@sentry/nextjs';
|
|
import * as trpcNext from '@trpc/server/adapters/next';
|
|
|
|
export default trpcNext.createNextApiHandler({
|
|
/**
|
|
* Enable query batching
|
|
*/
|
|
batching: {
|
|
enabled: true,
|
|
},
|
|
|
|
/**
|
|
* @link https://trpc.io/docs/context
|
|
*/
|
|
createContext,
|
|
|
|
/**
|
|
* @link https://trpc.io/docs/error-handling
|
|
*/
|
|
onError(opts) {
|
|
const { error } = opts;
|
|
// send to bug reporting
|
|
withScope((scope) => {
|
|
(Object.keys(opts) as Array<keyof typeof opts>).forEach((key) => {
|
|
if (key !== 'req') {
|
|
let extra = opts[key];
|
|
if (key === 'input') extra = JSON.stringify(extra);
|
|
scope.setExtra(key, extra);
|
|
}
|
|
});
|
|
captureException(error);
|
|
});
|
|
// eslint-disable-next-line no-console
|
|
console.error('Something went wrong', error);
|
|
},
|
|
|
|
router: appRouter,
|
|
/**
|
|
* @link https://trpc.io/docs/caching#api-response-caching
|
|
*/
|
|
// responseMeta() {
|
|
// // ...
|
|
// },
|
|
});
|