-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
1 parent
1bcaf37
commit 22eadbe
Showing
6 changed files
with
54 additions
and
6 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
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
2 changes: 1 addition & 1 deletion
2
dev-packages/e2e-tests/test-applications/nestjs-basic/src/example-global.filter.ts
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
5 changes: 5 additions & 0 deletions
5
dev-packages/e2e-tests/test-applications/nestjs-basic/src/example-local-filter.exception.ts
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,5 @@ | ||
export class ExampleExceptionLocalFilter extends Error { | ||
constructor() { | ||
super('Original local example exception!'); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
dev-packages/e2e-tests/test-applications/nestjs-basic/src/example-local.filter.ts
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,21 @@ | ||
import { ArgumentsHost, BadRequestException, Catch, ExceptionFilter } from '@nestjs/common'; | ||
import { Request, Response } from 'express'; | ||
import { ExampleExceptionLocalFilter } from './example-local-filter.exception'; | ||
|
||
@Catch(ExampleExceptionLocalFilter) | ||
export class ExampleLocalFilter implements ExceptionFilter { | ||
catch(exception: BadRequestException, host: ArgumentsHost): void { | ||
const ctx = host.switchToHttp(); | ||
const response = ctx.getResponse<Response>(); | ||
const request = ctx.getRequest<Request>(); | ||
const status = exception.getStatus(); | ||
console.log('Example local exception filter!'); | ||
|
||
response.status(status).json({ | ||
statusCode: 400, | ||
timestamp: new Date().toISOString(), | ||
path: request.url, | ||
message: 'Example exception was handled by local filter!', | ||
}); | ||
} | ||
} |
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