Skip to content

Commit 850535b

Browse files
committed
Reorder error handling
1 parent 3f0b539 commit 850535b

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

prometheus/promhttp/http.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,13 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO
191191
rsp.Header().Set(contentTypeHeader, string(contentType))
192192

193193
w, encodingHeader, closeWriter, err := NegotiateEncodingWriter(req, rsp, opts.DisableCompression, compressions)
194+
if err != nil {
195+
if opts.ErrorLog != nil {
196+
opts.ErrorLog.Println("error getting writer", err)
197+
}
198+
w = io.Writer(rsp)
199+
encodingHeader = string(Identity)
200+
}
194201

195202
if closeWriter != nil {
196203
defer func() {
@@ -202,17 +209,7 @@ func HandlerForTransactional(reg prometheus.TransactionalGatherer, opts HandlerO
202209
}
203210
}()
204211
}
205-
if err != nil {
206-
if opts.ErrorLog != nil {
207-
opts.ErrorLog.Println("error getting writer", err)
208-
}
209-
// Since the writer received from NegotiateEncodingWriter will be nil, in case there's an error, we set it here
210-
w = io.Writer(rsp)
211-
}
212212

213-
if encodingHeader == "" {
214-
encodingHeader = string(Identity)
215-
}
216213
rsp.Header().Set(contentEncodingHeader, encodingHeader)
217214

218215
enc := expfmt.NewEncoder(w, contentType)

0 commit comments

Comments
 (0)