From e3d363512032a994e63281fa4986066ce04ea1c4 Mon Sep 17 00:00:00 2001 From: Masoud Bahrami Date: Tue, 30 Jan 2024 14:08:16 +0330 Subject: [PATCH] Fix a bug in HttpRequesterMiddleware.cs, BadRequest should be logged as debug! --- .../Requester/Middleware/HttpRequesterMiddleware.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Ocelot/Requester/Middleware/HttpRequesterMiddleware.cs b/src/Ocelot/Requester/Middleware/HttpRequesterMiddleware.cs index e26d6a5b3..9c83a93f0 100644 --- a/src/Ocelot/Requester/Middleware/HttpRequesterMiddleware.cs +++ b/src/Ocelot/Requester/Middleware/HttpRequesterMiddleware.cs @@ -39,15 +39,14 @@ public async Task Invoke(HttpContext httpContext) private void CreateLogBasedOnResponse(Response response) { - if (response.Data?.StatusCode <= HttpStatusCode.BadRequest) + var message= () =>$"{(int)response.Data.StatusCode} ({response.Data.ReasonPhrase}) status code, request uri: {response.Data.RequestMessage?.RequestUri}"; + if (response.Data?.StatusCode < HttpStatusCode.BadRequest) { - Logger.LogInformation(() => - $"{(int)response.Data.StatusCode} ({response.Data.ReasonPhrase}) status code, request uri: {response.Data.RequestMessage?.RequestUri}"); + Logger.LogInformation(message); } else if (response.Data?.StatusCode >= HttpStatusCode.BadRequest) { - Logger.LogWarning( - () => $"{(int)response.Data.StatusCode} ({response.Data.ReasonPhrase}) status code, request uri: {response.Data.RequestMessage?.RequestUri}"); + Logger.LogWarning(message); } } }