Skip to content

Commit

Permalink
Merge pull request #165 from danielgtaylor/status-after-transform
Browse files Browse the repository at this point in the history
fix: set response status after transforms
  • Loading branch information
danielgtaylor authored Nov 6, 2023
2 parents 202c91e + c955c3a commit 3130224
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions huma.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ func transformAndWrite(api API, ctx Context, status int, ct string, body any) {
ctx.BodyWriter().Write([]byte("error transforming response"))
panic(fmt.Sprintf("error transforming response %+v for %s %s %d: %s\n", tval, ctx.Operation().Method, ctx.Operation().Path, status, terr.Error()))
}
ctx.SetStatus(status)
if merr := api.Marshal(ctx.BodyWriter(), ct, tval); merr != nil {
ctx.BodyWriter().Write([]byte("error marshaling response"))
panic(fmt.Sprintf("error marshaling response %+v for %s %s %d: %s\n", tval, ctx.Operation().Method, ctx.Operation().Path, status, merr.Error()))
Expand Down Expand Up @@ -916,7 +917,6 @@ func Register[I, O any](api API, op Operation, handler func(context.Context, *I)
ct = ctf.ContentType(ct)
}

ctx.SetStatus(status)
ctx.SetHeader("Content-Type", ct)
transformAndWrite(api, ctx, status, ct, err)
return
Expand Down Expand Up @@ -989,7 +989,6 @@ func Register[I, O any](api API, op Operation, handler func(context.Context, *I)
ctx.SetHeader("Content-Type", ct)
}

ctx.SetStatus(status)
transformAndWrite(api, ctx, status, ct, body)
} else {
ctx.SetStatus(status)
Expand Down

0 comments on commit 3130224

Please sign in to comment.