Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,7 @@ There are set of prepared errors you can use:
- NotAcceptableError
- NotFoundError
- UnauthorizedError
- UnprocessableEntityError

You can also create and use your own errors by extending `HttpError` class.
To define the data returned to the client, you could define a toJSON method in your error.
Expand Down
1 change: 1 addition & 0 deletions docs/lang/chinese/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ getOne(@Param("id") id: number) {
- NotAcceptableError
- NotFoundError
- UnauthorizedError
- UnprocessableEntityError

可以继承 `HttpError` 类自行创建使用 error。
也可实现一个 toJson 函数定义返回给客户端的数据。
Expand Down
1 change: 1 addition & 0 deletions lang/chinese/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,7 @@ getOne(@Param("id") id: number) {
- NotAcceptableError
- NotFoundError
- UnauthorizedError
- UnprocessableEntityError

可以继承 `HttpError` 类自行创建使用 error。
也可实现一个 toJson 函数定义返回给客户端的数据。
Expand Down
15 changes: 15 additions & 0 deletions src/http-error/UnprocessableEntityError.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { HttpError } from './HttpError';

/**
* Exception for 422 HTTP error.
*/
export class UnprocessableEntityError extends HttpError {
name = 'UnprocessableEntityError';

constructor(message?: string) {
super(422);
Object.setPrototypeOf(this, UnprocessableEntityError.prototype);

if (message) this.message = message;
}
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export * from './http-error/NotAcceptableError';
export * from './http-error/MethodNotAllowedError';
export * from './http-error/NotFoundError';
export * from './http-error/UnauthorizedError';
export * from './http-error/UnprocessableEntityError';

export * from './driver/express/ExpressMiddlewareInterface';
export * from './driver/express/ExpressErrorMiddlewareInterface';
Expand Down