feat: 增加全局错误捕捉及验证
This commit is contained in:
1 parent
235ca8c4aa
commit
bbf5360ef7
22 files changed
+273
-40
No files matched your search
+9
-6
@@ -3,6 +3,8 @@ import { AppModule } from './app.module';
|
||||
import { SnowflakeUtil } from './core/util/snowflake.util';
|
||||
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
|
||||
import { ValidationPipe } from '@nestjs/common';
|
||||
import { GlobalExceptionFilter } from './core/exceptions/global-exception.filter';
|
||||
import { GlobalValidationPipe } from './core/pipe/global-validation.pipe';
|
||||
|
||||
async function bootstrap() {
|
||||
SnowflakeUtil.initialize(
|
||||
@@ -15,16 +17,17 @@ async function bootstrap() {
|
||||
.setTitle(process.env.APP_TITLE)
|
||||
.setDescription('The api description')
|
||||
.setVersion('1.0')
|
||||
|
||||
.build();
|
||||
const document = SwaggerModule.createDocument(app, config);
|
||||
SwaggerModule.setup('docs', app, document);
|
||||
SwaggerModule.setup('docs', app, document, {
|
||||
jsonDocumentUrl: 'docs/json',
|
||||
});
|
||||
}
|
||||
|
||||
app.useGlobalPipes(
|
||||
new ValidationPipe({
|
||||
transform: true,
|
||||
}),
|
||||
);
|
||||
app.useGlobalPipes(new GlobalValidationPipe());
|
||||
app.useGlobalFilters(new GlobalExceptionFilter());
|
||||
|
||||
await app.listen(3000);
|
||||
}
|
||||
bootstrap();
|
||||
Reference in new issue
Block a user