File tree Expand file tree Collapse file tree 5 files changed +19
-0
lines changed Expand file tree Collapse file tree 5 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -766,6 +766,7 @@ There are set of prepared errors you can use:
766766- NotAcceptableError
767767- NotFoundError
768768- UnauthorizedError
769+ - UnprocessableEntityError
769770
770771You can also create and use your own errors by extending ` HttpError ` class.
771772To define the data returned to the client, you could define a toJSON method in your error.
Original file line number Diff line number Diff line change @@ -724,6 +724,7 @@ getOne(@Param("id") id: number) {
724724- NotAcceptableError
725725- NotFoundError
726726- UnauthorizedError
727+ - UnprocessableEntityError
727728
728729可以继承 ` HttpError ` 类自行创建使用 error。
729730也可实现一个 toJson 函数定义返回给客户端的数据。
Original file line number Diff line number Diff line change @@ -727,6 +727,7 @@ getOne(@Param("id") id: number) {
727727- NotAcceptableError
728728- NotFoundError
729729- UnauthorizedError
730+ - UnprocessableEntityError
730731
731732可以继承 ` HttpError ` 类自行创建使用 error。
732733也可实现一个 toJson 函数定义返回给客户端的数据。
Original file line number Diff line number Diff line change 1+ import { HttpError } from './HttpError' ;
2+
3+ /**
4+ * Exception for 422 HTTP error.
5+ */
6+ export class UnprocessableEntityError extends HttpError {
7+ name = 'UnprocessableEntityError' ;
8+
9+ constructor ( message ?: string ) {
10+ super ( 422 ) ;
11+ Object . setPrototypeOf ( this , UnprocessableEntityError . prototype ) ;
12+
13+ if ( message ) this . message = message ;
14+ }
15+ }
Original file line number Diff line number Diff line change @@ -71,6 +71,7 @@ export * from './http-error/NotAcceptableError';
7171export * from './http-error/MethodNotAllowedError' ;
7272export * from './http-error/NotFoundError' ;
7373export * from './http-error/UnauthorizedError' ;
74+ export * from './http-error/UnprocessableEntityError' ;
7475
7576export * from './driver/express/ExpressMiddlewareInterface' ;
7677export * from './driver/express/ExpressErrorMiddlewareInterface' ;
You can’t perform that action at this time.
0 commit comments