-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
docs(js): Review and update Nest.js Quick Start guide #13497
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5427ba1
review and update Nest.js Quick Start guide
inventarSarah 90ab40a
Merge branch 'master' of github.com:getsentry/sentry-docs into smi/qu…
inventarSarah bb448d1
PR feedback
inventarSarah 352fc65
Update platform-includes/getting-started-use/javascript.nestjs.mdx
inventarSarah 3c54163
Merge branch 'master' of github.com:getsentry/sentry-docs into smi/qu…
inventarSarah bd7fea7
update guide to TS and create new step for Error Capturing
inventarSarah 17472be
create and use new platform include for capturing error content
inventarSarah 3995e01
Merge branch 'master' of github.com:getsentry/sentry-docs into smi/qu…
inventarSarah d443895
pr feedback - rewrite subheadings
inventarSarah 59e2357
Merge branch 'master' of github.com:getsentry/sentry-docs into smi/qu…
inventarSarah 6e33498
remove duplicate includes
inventarSarah 8f78185
Merge branch 'master' of github.com:getsentry/sentry-docs into smi/qu…
inventarSarah File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
84 changes: 84 additions & 0 deletions
84
platform-includes/getting-started-capture-errors/javascript.nestjs.mdx
This file contains hidden or 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,84 @@ | ||
By default, Sentry only captures unhandled exceptions that aren't caught by an error filter. | ||
Additionally, `HttpException`s (including [derivatives](https://docs.nestjs.com/exception-filters#built-in-http-exceptions)) aren't captured by default because they mostly act as control flow vehicles. | ||
|
||
To make sure Sentry captures all your app's errors, configure error handling based on how your application manages exceptions: | ||
|
||
### Using a Custom Global Filter | ||
|
||
If you have a global catch-all exception filter, add a `@SentryExceptionCaptured()` decorator to the filter's `catch()` method: | ||
|
||
```typescript {2, 6} | ||
import { Catch, ExceptionFilter } from "@nestjs/common"; | ||
import { SentryExceptionCaptured } from "@sentry/nestjs"; | ||
|
||
@Catch() | ||
export class YourCatchAllExceptionFilter implements ExceptionFilter { | ||
@SentryExceptionCaptured() | ||
catch(exception, host): void { | ||
// your implementation here | ||
} | ||
} | ||
``` | ||
|
||
### Not Using a Custom Global Filter | ||
|
||
If you don't have a global catch-all exception filter, add the `SentryGlobalFilter` to the providers of your main module, **before** any other exception filters: | ||
|
||
```typescript {2-3, 7-10} | ||
import { Module } from "@nestjs/common"; | ||
import { APP_FILTER } from "@nestjs/core"; | ||
import { SentryGlobalFilter } from "@sentry/nestjs/setup"; | ||
|
||
@Module({ | ||
providers: [ | ||
{ | ||
provide: APP_FILTER, | ||
useClass: SentryGlobalFilter, | ||
}, | ||
// ..other providers | ||
], | ||
}) | ||
export class AppModule {} | ||
``` | ||
|
||
### Using Error Filters for Specific Exception Types | ||
|
||
If you have error filters for specific types of exceptions (for example, `@Catch(HttpException)`) and you want to report these errors to Sentry, you need to capture them in the `catch()` handler using `Sentry.captureException()`: | ||
|
||
```typescript {4,9} | ||
import { ArgumentsHost, BadRequestException, Catch } from "@nestjs/common"; | ||
import { BaseExceptionFilter } from "@nestjs/core"; | ||
import { ExampleException } from "./example.exception"; | ||
import * as Sentry from "@sentry/nestjs"; | ||
|
||
@Catch(ExampleException) | ||
export class ExampleExceptionFilter extends BaseExceptionFilter { | ||
catch(exception: unknown, host: ArgumentsHost) { | ||
Sentry.captureException(exception); | ||
return super.catch(new BadRequestException(exception.message), host); | ||
} | ||
} | ||
``` | ||
|
||
<Expandable title="Are you using Microservices?"> | ||
If you're using `@nestjs/microservices` make sure to handle errors in RPC contexts correctly by providing your own `RpcExceptionFilter` (see [Nest.js Microservices documentation](https://docs.nestjs.com/microservices/exception-filters)). | ||
`SentryGlobalFilter` in a [hybrid application](https://docs.nestjs.com/faq/hybrid-application) doesn't extend `BaseRpcExceptionFilter` since this depends on `@nestjs/microservices`. | ||
|
||
Use `Sentry.captureException(exception)` in your custom filter in case you want to send these errors to Sentry: | ||
|
||
```typescript | ||
import { Catch, RpcExceptionFilter, ArgumentsHost } from "@nestjs/common"; | ||
import { Observable, throwError } from "rxjs"; | ||
import { RpcException } from "@nestjs/microservices"; | ||
import * as Sentry from "@sentry/nestjs"; | ||
|
||
@Catch(RpcException) | ||
export class ExceptionFilter implements RpcExceptionFilter<RpcException> { | ||
catch(exception: RpcException, host: ArgumentsHost): Observable<any> { | ||
Sentry.captureException(exception); // optional | ||
return throwError(() => exception.getError()); | ||
} | ||
} | ||
``` | ||
|
||
</Expandable> |
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think? 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both forms are correct, although the variant with “s” is used in British English and the one without in American English 👍