Skip to content

Commit

Permalink
feat: added unprocessable entity (422) http error (#1459)
Browse files Browse the repository at this point in the history
  • Loading branch information
shevchenkonik authored Nov 23, 2024
1 parent 31de88c commit 94175af
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
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

0 comments on commit 94175af

Please sign in to comment.