From b9cb052819d6c8bd314b392ae6cfb90f656e3cec Mon Sep 17 00:00:00 2001 From: waldekmastykarz Date: Tue, 21 Nov 2023 11:17:55 +0100 Subject: [PATCH] Extends RetryAfterPlugin with a clearer error message --- dev-proxy-plugins/Behavior/RetryAfterPlugin.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/dev-proxy-plugins/Behavior/RetryAfterPlugin.cs b/dev-proxy-plugins/Behavior/RetryAfterPlugin.cs index 3f9b2432..9733f138 100644 --- a/dev-proxy-plugins/Behavior/RetryAfterPlugin.cs +++ b/dev-proxy-plugins/Behavior/RetryAfterPlugin.cs @@ -56,16 +56,17 @@ private void ThrottleIfNecessary(ProxyRequestArgs e) var throttleInfo = throttler.ShouldThrottle(request, throttler.ThrottlingKey); if (throttleInfo.ThrottleForSeconds > 0) { - _logger?.LogRequest(new[] { $"Calling {request.Url} before waiting for the Retry-After period.", "Request will be throttled", $"Throttling on {throttler.ThrottlingKey}" }, MessageType.Failed, new LoggingContext(e.Session)); + var messageLines = new[] { $"Calling {request.Url} before waiting for the Retry-After period.", "Request will be throttled.", $"Throttling on {throttler.ThrottlingKey}." }; + _logger?.LogRequest(messageLines, MessageType.Failed, new LoggingContext(e.Session)); throttler.ResetTime = DateTime.Now.AddSeconds(throttleInfo.ThrottleForSeconds); - UpdateProxyResponse(e, throttleInfo); + UpdateProxyResponse(e, throttleInfo, string.Join(' ', messageLines)); break; } } } - private void UpdateProxyResponse(ProxyRequestArgs e, ThrottlingInfo throttlingInfo) + private void UpdateProxyResponse(ProxyRequestArgs e, ThrottlingInfo throttlingInfo, string message) { var headers = new List(); var body = string.Empty; @@ -82,7 +83,7 @@ private void UpdateProxyResponse(ProxyRequestArgs e, ThrottlingInfo throttlingIn new GraphErrorResponseError { Code = new Regex("([A-Z])").Replace(HttpStatusCode.TooManyRequests.ToString(), m => { return $" {m.Groups[1]}"; }).Trim(), - Message = BuildApiErrorMessage(request), + Message = BuildApiErrorMessage(request, message), InnerError = new GraphErrorResponseInnerError { RequestId = requestId, @@ -98,5 +99,5 @@ private void UpdateProxyResponse(ProxyRequestArgs e, ThrottlingInfo throttlingIn e.ResponseState.HasBeenSet = true; } - private static string BuildApiErrorMessage(Request r) => $"Some error was generated by the proxy. {(ProxyUtils.IsGraphRequest(r) ? ProxyUtils.IsSdkRequest(r) ? "" : String.Join(' ', MessageUtils.BuildUseSdkForErrorsMessage(r)) : "")}"; + private static string BuildApiErrorMessage(Request r, string message) => $"{message} {(ProxyUtils.IsGraphRequest(r) ? ProxyUtils.IsSdkRequest(r) ? "" : string.Join(' ', MessageUtils.BuildUseSdkForErrorsMessage(r)) : "")}"; }