From facbeeacd6c0cd936ce974157b827e57533c8eea Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Mon, 27 Mar 2023 15:29:00 +0100 Subject: [PATCH] feat: Add support for HTTP status 422 (Unprocessable Content) (#4080) --- packages/server/src/http/getHTTPStatusCode.ts | 1 + packages/server/src/rpc/codes.ts | 1 + www/docs/server/error-handling.md | 1 + 3 files changed, 3 insertions(+) diff --git a/packages/server/src/http/getHTTPStatusCode.ts b/packages/server/src/http/getHTTPStatusCode.ts index 571cf0cb4e0..84f3656538b 100644 --- a/packages/server/src/http/getHTTPStatusCode.ts +++ b/packages/server/src/http/getHTTPStatusCode.ts @@ -22,6 +22,7 @@ const JSONRPC2_TO_HTTP_CODE: Record< PRECONDITION_FAILED: 412, PAYLOAD_TOO_LARGE: 413, METHOD_NOT_SUPPORTED: 405, + UNPROCESSABLE_CONTENT: 422, TOO_MANY_REQUESTS: 429, }; diff --git a/packages/server/src/rpc/codes.ts b/packages/server/src/rpc/codes.ts index 70251dbeb41..aa81bf2c741 100644 --- a/packages/server/src/rpc/codes.ts +++ b/packages/server/src/rpc/codes.ts @@ -31,6 +31,7 @@ export const TRPC_ERROR_CODES_BY_KEY = { CONFLICT: -32009, // 409 PRECONDITION_FAILED: -32012, // 412 PAYLOAD_TOO_LARGE: -32013, // 413 + UNPROCESSABLE_CONTENT: -32022, // 422 TOO_MANY_REQUESTS: -32029, // 429 CLIENT_CLOSED_REQUEST: -32099, // 499 } as const; diff --git a/www/docs/server/error-handling.md b/www/docs/server/error-handling.md index d143a393ce8..d705b572f5e 100644 --- a/www/docs/server/error-handling.md +++ b/www/docs/server/error-handling.md @@ -42,6 +42,7 @@ tRPC defines a list of error codes that each represent a different type of error | PRECONDITION_FAILED | Access to the target resource has been denied. | 412 | | PAYLOAD_TOO_LARGE | Request entity is larger than limits defined by server. | 413 | | METHOD_NOT_SUPPORTED | The server knows the request method, but the target resource doesn't support this method. | 405 | +| UNPROCESSABLE_CONTENT | The server understands the request method, and the request entity is correct, but the server was unable to process it. | 422 | | TOO_MANY_REQUESTS | The rate limit has been exceeded or too many requests are being sent to the server. | 429 | | CLIENT_CLOSED_REQUEST | Access to the resource has been denied. | 499 | | INTERNAL_SERVER_ERROR | An unspecified error occurred. | 500 |