Adds callback failure logging
All checks were successful
Build and Push Docker Images / build (src/LiquidCode.Tester.Gateway/Dockerfile, git.nullptr.top/liquidcode/liquidcode-tester-gateway-roman, gateway) (push) Successful in 46s
Build and Push Docker Images / build (src/LiquidCode.Tester.Worker/Dockerfile, git.nullptr.top/liquidcode/liquidcode-tester-worker-roman, worker) (push) Successful in 1m2s
All checks were successful
Build and Push Docker Images / build (src/LiquidCode.Tester.Gateway/Dockerfile, git.nullptr.top/liquidcode/liquidcode-tester-gateway-roman, gateway) (push) Successful in 46s
Build and Push Docker Images / build (src/LiquidCode.Tester.Worker/Dockerfile, git.nullptr.top/liquidcode/liquidcode-tester-worker-roman, worker) (push) Successful in 1m2s
Adds logging for non-success status codes returned by the callback URL. This improves debugging by providing visibility into callback failures, including the status code and a truncated response body.
This commit is contained in:
@@ -33,6 +33,14 @@ public class CallbackService : ICallbackService
|
|||||||
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||||
|
|
||||||
var httpResponse = await httpClient.PostAsync(callbackUrl, content);
|
var httpResponse = await httpClient.PostAsync(callbackUrl, content);
|
||||||
|
|
||||||
|
if (!httpResponse.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
var responseBody = await httpResponse.Content.ReadAsStringAsync();
|
||||||
|
_logger.LogWarning("Callback returned non-success status {StatusCode} with body: {Body}",
|
||||||
|
(int)httpResponse.StatusCode, Truncate(responseBody, 2048));
|
||||||
|
}
|
||||||
|
|
||||||
httpResponse.EnsureSuccessStatusCode();
|
httpResponse.EnsureSuccessStatusCode();
|
||||||
|
|
||||||
_logger.LogInformation("Status update sent successfully");
|
_logger.LogInformation("Status update sent successfully");
|
||||||
@@ -44,6 +52,16 @@ public class CallbackService : ICallbackService
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string Truncate(string value, int maxLength)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(value) || value.Length <= maxLength)
|
||||||
|
{
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value.Substring(0, maxLength) + "…";
|
||||||
|
}
|
||||||
|
|
||||||
private bool IsLogCallback(string callbackUrl)
|
private bool IsLogCallback(string callbackUrl)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(callbackUrl))
|
if (string.IsNullOrWhiteSpace(callbackUrl))
|
||||||
|
|||||||
Reference in New Issue
Block a user