Skip to content

Commit

Permalink
fix(logging): silence UnauthorizedException for sentry (#139)
Browse files Browse the repository at this point in the history
see #138
  • Loading branch information
sleidig authored Apr 2, 2024
1 parent c6d2e56 commit 81a7d29
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/sentry.configuration.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import * as Sentry from '@sentry/node';
import { ConfigService } from '@nestjs/config';
import { ArgumentsHost, INestApplication } from '@nestjs/common';
import {
ArgumentsHost,
INestApplication,
UnauthorizedException,
} from '@nestjs/common';
import { BaseExceptionFilter, HttpAdapterHost } from '@nestjs/core';

export class SentryConfiguration {
Expand Down Expand Up @@ -56,6 +60,16 @@ function configureLoggingSentry(
tracesSampleRate: 1.0, // Capture 100% of the transactions
// Set sampling rate for profiling - this is relative to tracesSampleRate
profilesSampleRate: 1.0,

beforeSend: (event, hint) => {
const error = hint.originalException;
if (error instanceof UnauthorizedException) {
console.log(error);
return null;
}

return event;
},
});

app.use(Sentry.Handlers.errorHandler());
Expand Down

0 comments on commit 81a7d29

Please sign in to comment.