Skip to content

Commit

Permalink
Reorder error handling
Browse files Browse the repository at this point in the history
Signed-off-by: Manuel Rüger <[email protected]>
  • Loading branch information
mrueg committed Jun 5, 2024
1 parent f0c8656 commit 9fea575
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions prometheus/promhttp/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO
rsp.Header().Set(contentTypeHeader, string(contentType))

w, encodingHeader, closeWriter, err := NegotiateEncodingWriter(req, rsp, opts.DisableCompression, compressions)
if err != nil {
if opts.ErrorLog != nil {
opts.ErrorLog.Println("error getting writer", err)
}
w = io.Writer(rsp)
encodingHeader = string(Identity)
}

if closeWriter != nil {
defer func() {
Expand All @@ -202,17 +209,7 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO
}
}()
}
if err != nil {
if opts.ErrorLog != nil {
opts.ErrorLog.Println("error getting writer", err)
}
// Since the writer received from NegotiateEncodingWriter will be nil, in case there's an error, we set it here
w = io.Writer(rsp)
}

if encodingHeader == "" {
encodingHeader = string(Identity)
}
rsp.Header().Set(contentEncodingHeader, encodingHeader)

enc := expfmt.NewEncoder(w, contentType)
Expand Down

0 comments on commit 9fea575

Please sign in to comment.