* custom error component
* upload sourcemaps to sentry * report caught errors to sentry
This commit is contained in:
34
integrations/sentry.ts
Normal file
34
integrations/sentry.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import * as Sentry from "@sentry/node";
|
||||
import getConfig from "next/config";
|
||||
import { RewriteFrames } from "@sentry/integrations";
|
||||
|
||||
if (process.env.SENTRY_DSN) {
|
||||
const config = getConfig();
|
||||
const distDir = `${config.serverRuntimeConfig.rootDir}/.next`;
|
||||
Sentry.init({
|
||||
integrations: [
|
||||
new RewriteFrames({
|
||||
iteratee: (frame: any) => {
|
||||
frame.filename = frame.filename.replace(distDir, "app:///_next");
|
||||
return frame;
|
||||
},
|
||||
}),
|
||||
],
|
||||
dsn: process.env.SENTRY_DSN,
|
||||
beforeSend(event, hint) {
|
||||
const error = hint?.originalException;
|
||||
if (error && typeof error !== "string") {
|
||||
switch (error.name) {
|
||||
case "AuthenticationError":
|
||||
case "AuthorizationError":
|
||||
case "NotFoundError":
|
||||
case "ChunkLoadError":
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return event;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export default Sentry;
|
Reference in New Issue
Block a user