-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,572 additions
and
1,798 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Catch, ExceptionFilter, HttpException, HttpStatus, Logger } from '@nestjs/common'; | ||
import { WithSentry } from '@sentry/nestjs'; | ||
import { ArgumentsHost } from '@nestjs/common'; | ||
|
||
@Catch() | ||
export class GlobalExceptionFilter implements ExceptionFilter { | ||
private readonly logger = new Logger(GlobalExceptionFilter.name); | ||
|
||
@WithSentry() | ||
catch(exception: any, host: ArgumentsHost): void { | ||
const ctx = host.switchToHttp(); | ||
const response = ctx.getResponse(); | ||
const request = ctx.getRequest(); | ||
|
||
const status = | ||
exception instanceof HttpException | ||
? exception.getStatus() | ||
: HttpStatus.INTERNAL_SERVER_ERROR; | ||
|
||
const message = | ||
exception instanceof HttpException | ||
? exception.message | ||
: 'Internal server error'; | ||
|
||
// Only log to Sentry if not in local development | ||
if (process.env.NODE_ENV !== 'local') { | ||
this.logger.error({ | ||
statusCode: status, | ||
timestamp: new Date().toISOString(), | ||
path: request.url, | ||
message, | ||
stack: exception.stack, | ||
environment: process.env.NODE_ENV | ||
}); | ||
} | ||
|
||
response.status(status).json({ | ||
statusCode: status, | ||
timestamp: new Date().toISOString(), | ||
path: request.url, | ||
message | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { ExceptionFilter, Catch, ArgumentsHost, HttpException, HttpStatus } from '@nestjs/common'; | ||
import { Response } from 'express'; | ||
import * as Sentry from '@sentry/node'; | ||
|
||
@Catch() | ||
export class SentryFilter implements ExceptionFilter { | ||
catch(exception: unknown, host: ArgumentsHost) { | ||
const ctx = host.switchToHttp(); | ||
const response = ctx.getResponse<Response>(); | ||
|
||
Sentry.captureException(exception); | ||
|
||
const status = | ||
exception instanceof HttpException | ||
? exception.getStatus() | ||
: HttpStatus.INTERNAL_SERVER_ERROR; | ||
|
||
response.status(status).json({ | ||
statusCode: status, | ||
timestamp: new Date().toISOString(), | ||
message: 'Internal server error' | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Import with `const Sentry = require("@sentry/nestjs");` if you are using CJS | ||
import * as Sentry from "@sentry/nestjs" | ||
|
||
Sentry.init({ | ||
dsn: "https://714f3c892f47269a430f97326ca12ac0@o4508380579430400.ingest.de.sentry.io/4508380581789776", | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters