Skip to content

Commit 673dddb

Browse files
committed
Fix order of http message handler to ensure unsuccessful requests can be traced
1 parent 12ee30a commit 673dddb

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

src/Dibix.Http.Client/Client/DefaultHttpClientFactory.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,14 +341,14 @@ public void ConfigureDefaults()
341341
if (this.TraceProxy)
342342
this.AddHttpMessageHandler<TraceProxyHttpMessageHandler>();
343343

344+
// Add this before each handler, that needs to access the response, before an exception is thrown. (i.E. TracingHttpMessageHandler)
345+
if (this.EnsureSuccessStatusCode)
346+
this.AddHttpMessageHandler<EnsureSuccessStatusCodeHttpMessageHandler>();
347+
344348
// Run tracing after all other handlers, that potentially modified the request, to ensure the trace includes the actual request that is sent.
345349
if (this.Tracer != null)
346350
this.AddHttpMessageHandler(() => new TracingHttpMessageHandler(this.Tracer));
347351

348-
// Add this after each handler, that needs to access the response, before an exception is thrown. (i.E. TracingHttpMessageHandler)
349-
if (this.EnsureSuccessStatusCode)
350-
this.AddHttpMessageHandler<EnsureSuccessStatusCodeHttpMessageHandler>();
351-
352352
// This should be as close to the primary handler as possible to avoid timeouts caused by other handlers.
353353
if (this.WrapTimeoutsInException)
354354
this.AddHttpMessageHandler<TimeoutHttpMessageHandler>();

0 commit comments

Comments
 (0)