-
-
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.
test(e2e): Add nestjs e2e test documenting errors not being properly …
…caught in submodules (#12868)
- Loading branch information
1 parent
00fabe5
commit 0e6d802
Showing
6 changed files
with
77 additions
and
1 deletion.
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
12 changes: 12 additions & 0 deletions
12
dev-packages/e2e-tests/test-applications/nestjs/src/test-module/test.controller.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,12 @@ | ||
import { Controller, Get } from '@nestjs/common'; | ||
import { TestException } from './test.exception'; | ||
|
||
@Controller('test-module') | ||
export class TestController { | ||
constructor() {} | ||
|
||
@Get() | ||
getTest(): string { | ||
throw new TestException(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
dev-packages/e2e-tests/test-applications/nestjs/src/test-module/test.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 TestException extends Error { | ||
constructor() { | ||
super('Something went wrong in the test module!'); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
dev-packages/e2e-tests/test-applications/nestjs/src/test-module/test.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,13 @@ | ||
import { ArgumentsHost, BadRequestException, Catch } from '@nestjs/common'; | ||
import { BaseExceptionFilter } from '@nestjs/core'; | ||
import { TestException } from './test.exception'; | ||
|
||
@Catch(TestException) | ||
export class TestExceptionFilter extends BaseExceptionFilter { | ||
catch(exception: unknown, host: ArgumentsHost) { | ||
if (exception instanceof TestException) { | ||
return super.catch(new BadRequestException(exception.message), host); | ||
} | ||
return super.catch(exception, host); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
dev-packages/e2e-tests/test-applications/nestjs/src/test-module/test.module.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,16 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { APP_FILTER } from '@nestjs/core'; | ||
import { TestController } from './test.controller'; | ||
import { TestExceptionFilter } from './test.filter'; | ||
|
||
@Module({ | ||
imports: [], | ||
controllers: [TestController], | ||
providers: [ | ||
{ | ||
provide: APP_FILTER, | ||
useClass: TestExceptionFilter, | ||
}, | ||
], | ||
}) | ||
export class TestModule {} |
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