Skip to content

Commit

Permalink
Merge pull request #390 from danielgtaylor/fix-204-304-body
Browse files Browse the repository at this point in the history
fix: do no try to write 204/304 body if present
  • Loading branch information
danielgtaylor authored Apr 19, 2024
2 parents 5a8a1f2 + e568619 commit e66ddf3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions huma.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}

Expand Down

0 comments on commit e66ddf3

Please sign in to comment.