Skip to content

Commit b9cb052

Browse files
Extends RetryAfterPlugin with a clearer error message
1 parent f4d0b2b commit b9cb052

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

dev-proxy-plugins/Behavior/RetryAfterPlugin.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,17 @@ private void ThrottleIfNecessary(ProxyRequestArgs e)
5656
var throttleInfo = throttler.ShouldThrottle(request, throttler.ThrottlingKey);
5757
if (throttleInfo.ThrottleForSeconds > 0)
5858
{
59-
_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));
59+
var messageLines = new[] { $"Calling {request.Url} before waiting for the Retry-After period.", "Request will be throttled.", $"Throttling on {throttler.ThrottlingKey}." };
60+
_logger?.LogRequest(messageLines, MessageType.Failed, new LoggingContext(e.Session));
6061

6162
throttler.ResetTime = DateTime.Now.AddSeconds(throttleInfo.ThrottleForSeconds);
62-
UpdateProxyResponse(e, throttleInfo);
63+
UpdateProxyResponse(e, throttleInfo, string.Join(' ', messageLines));
6364
break;
6465
}
6566
}
6667
}
6768

68-
private void UpdateProxyResponse(ProxyRequestArgs e, ThrottlingInfo throttlingInfo)
69+
private void UpdateProxyResponse(ProxyRequestArgs e, ThrottlingInfo throttlingInfo, string message)
6970
{
7071
var headers = new List<HttpHeader>();
7172
var body = string.Empty;
@@ -82,7 +83,7 @@ private void UpdateProxyResponse(ProxyRequestArgs e, ThrottlingInfo throttlingIn
8283
new GraphErrorResponseError
8384
{
8485
Code = new Regex("([A-Z])").Replace(HttpStatusCode.TooManyRequests.ToString(), m => { return $" {m.Groups[1]}"; }).Trim(),
85-
Message = BuildApiErrorMessage(request),
86+
Message = BuildApiErrorMessage(request, message),
8687
InnerError = new GraphErrorResponseInnerError
8788
{
8889
RequestId = requestId,
@@ -98,5 +99,5 @@ private void UpdateProxyResponse(ProxyRequestArgs e, ThrottlingInfo throttlingIn
9899
e.ResponseState.HasBeenSet = true;
99100
}
100101

101-
private static string BuildApiErrorMessage(Request r) => $"Some error was generated by the proxy. {(ProxyUtils.IsGraphRequest(r) ? ProxyUtils.IsSdkRequest(r) ? "" : String.Join(' ', MessageUtils.BuildUseSdkForErrorsMessage(r)) : "")}";
102+
private static string BuildApiErrorMessage(Request r, string message) => $"{message} {(ProxyUtils.IsGraphRequest(r) ? ProxyUtils.IsSdkRequest(r) ? "" : string.Join(' ', MessageUtils.BuildUseSdkForErrorsMessage(r)) : "")}";
102103
}

0 commit comments

Comments
 (0)