使用上了自定义的filter来处理异常,需要注意是引入filter的路径问题,从当前往上找两层文件夹就可以,其它src开头的相对路径不行
This commit is contained in:
parent
0e349316f8
commit
8ef85cd82e
|
@ -1,6 +1,7 @@
|
||||||
import { Controller, Get, Post, Req, Query, Headers, Param, Body, HttpException, HttpStatus, ForbiddenException } from '@nestjs/common';
|
import { Controller, Get, Post, Req, Query, Headers, Param, Body, HttpException, HttpStatus, ForbiddenException, UseFilters } from '@nestjs/common';
|
||||||
import { CreatePostDto } from './post.dto';
|
import { CreatePostDto } from './post.dto';
|
||||||
import { DemoService } from './providers/demo/demo.service'
|
import { DemoService } from './providers/demo/demo.service'
|
||||||
|
import { DemoFilter } from '../../core/filters/demo.filter'
|
||||||
|
|
||||||
|
|
||||||
@Controller('posts')
|
@Controller('posts')
|
||||||
|
@ -21,6 +22,7 @@ export class PostsController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
|
@UseFilters(DemoFilter)
|
||||||
store(@Body() post: CreatePostDto) {
|
store(@Body() post: CreatePostDto) {
|
||||||
// throw new HttpException('没有权限!', HttpStatus.FORBIDDEN)
|
// throw new HttpException('没有权限!', HttpStatus.FORBIDDEN)
|
||||||
throw new ForbiddenException('没有权限!')
|
throw new ForbiddenException('没有权限!')
|
||||||
|
|
Loading…
Reference in New Issue