Skip to content

Commit 6442030

Browse files
Fixes simulating throttling for batch Graph requests. Closes #1363 (#1364)
1 parent 1485aad commit 6442030

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

DevProxy.Plugins/Behavior/GraphRandomErrorPlugin.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,13 @@ private void FailBatch(ProxyRequestArgs e)
259259
{
260260
var retryAfterDate = DateTime.Now.AddSeconds(Configuration.RetryAfterInSeconds);
261261
var requestUrl = ProxyUtils.GetAbsoluteRequestUrlFromBatch(e.Session.HttpClient.Request.RequestUri, request.Url);
262-
var throttledRequests = e.GlobalData[RetryAfterPlugin.ThrottledRequestsKey] as List<ThrottlerInfo>;
262+
263+
if (!e.GlobalData.TryGetValue(RetryAfterPlugin.ThrottledRequestsKey, out var value))
264+
{
265+
value = new List<ThrottlerInfo>();
266+
e.GlobalData.Add(RetryAfterPlugin.ThrottledRequestsKey, value);
267+
}
268+
var throttledRequests = value as List<ThrottlerInfo>;
263269
throttledRequests?.Add(new(GraphUtils.BuildThrottleKey(requestUrl), ShouldThrottle, retryAfterDate));
264270
response.Headers = new() { { "Retry-After", Configuration.RetryAfterInSeconds.ToString(CultureInfo.InvariantCulture) } };
265271
}

0 commit comments

Comments
 (0)