From e568619d967bea79316c0757a9bfbbe33d42cf8e Mon Sep 17 00:00:00 2001 From: "Daniel G. Taylor" Date: Thu, 18 Apr 2024 22:13:02 -0700 Subject: [PATCH] fix: do no try to write 204/304 body if present --- huma.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/huma.go b/huma.go index 5e8dd743..899c7820 100644 --- a/huma.go +++ b/huma.go @@ -477,9 +477,11 @@ func transformAndWrite(api API, ctx Context, status int, ct string, body any) { panic(fmt.Errorf("error transforming response %+v for %s %s %d: %w\n", tval, ctx.Operation().Method, ctx.Operation().Path, status, terr)) } ctx.SetStatus(status) - if merr := api.Marshal(ctx.BodyWriter(), ct, tval); merr != nil { - ctx.BodyWriter().Write([]byte("error marshaling response")) - panic(fmt.Errorf("error marshaling response %+v for %s %s %d: %w\n", tval, ctx.Operation().Method, ctx.Operation().Path, status, merr)) + if status != http.StatusNoContent && status != http.StatusNotModified { + if merr := api.Marshal(ctx.BodyWriter(), ct, tval); merr != nil { + ctx.BodyWriter().Write([]byte("error marshaling response")) + panic(fmt.Errorf("error marshaling response %+v for %s %s %d: %w\n", tval, ctx.Operation().Method, ctx.Operation().Path, status, merr)) + } } }