From f809744a28cfabc9b53f06dbbb23e9b10377b41a Mon Sep 17 00:00:00 2001 From: "Daniel G. Taylor" Date: Thu, 14 Apr 2022 15:53:24 -0700 Subject: [PATCH] fix: add 422 convenience response --- responses/responses.go | 5 +++++ responses/responses_test.go | 2 ++ 2 files changed, 7 insertions(+) diff --git a/responses/responses.go b/responses/responses.go index 08c1636c..b6c8f8f4 100644 --- a/responses/responses.go +++ b/responses/responses.go @@ -113,6 +113,11 @@ func RequestEntityTooLarge() huma.Response { return errorResponse(http.StatusRequestEntityTooLarge) } +// UnprocessableEntity HTTP 422 response with a structured error body (e.g. JSON). +func UnprocessableEntity() huma.Response { + return errorResponse(http.StatusUnprocessableEntity) +} + // PreconditionRequired HTTP 428 response with a structured error body (e.g. JSON). func PreconditionRequired() huma.Response { return errorResponse(http.StatusPreconditionRequired) diff --git a/responses/responses_test.go b/responses/responses_test.go index 548d04fc..f037580f 100644 --- a/responses/responses_test.go +++ b/responses/responses_test.go @@ -34,6 +34,7 @@ var funcs = struct { Conflict, PreconditionFailed, RequestEntityTooLarge, + UnprocessableEntity, PreconditionRequired, InternalServerError, NotImplemented, @@ -71,6 +72,7 @@ func TestResponses(t *testing.T) { http.StatusConflict, http.StatusPreconditionFailed, http.StatusRequestEntityTooLarge, + http.StatusUnprocessableEntity, http.StatusPreconditionRequired, http.StatusInternalServerError, http.StatusNotImplemented,