Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Unprocessable Entity (422) HTTP Error #1459

Merged
merged 5 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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';

Check warning on line 7 in src/http-error/UnprocessableEntityError.ts

View check run for this annotation

Codecov / codecov/patch

src/http-error/UnprocessableEntityError.ts#L7

Added line #L7 was not covered by tests

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

Check warning on line 11 in src/http-error/UnprocessableEntityError.ts

View check run for this annotation

Codecov / codecov/patch

src/http-error/UnprocessableEntityError.ts#L10-L11

Added lines #L10 - L11 were not covered by tests

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
Loading