@@ -24,6 +24,7 @@ internal enum GraphRandomErrorFailMode
24
24
public class GraphRandomErrorConfiguration
25
25
{
26
26
public List < int > AllowedErrors { get ; set ; } = new ( ) ;
27
+ public int RetryAfterInSeconds { get ; set ; } = 5 ;
27
28
}
28
29
29
30
public class GraphRandomErrorPlugin : BaseProxyPlugin
@@ -34,7 +35,6 @@ public class GraphRandomErrorPlugin : BaseProxyPlugin
34
35
35
36
public override string Name => nameof ( GraphRandomErrorPlugin ) ;
36
37
37
- private const int retryAfterInSeconds = 5 ;
38
38
private readonly Dictionary < string , HttpStatusCode [ ] > _methodStatusCode = new ( )
39
39
{
40
40
{
@@ -140,11 +140,11 @@ private void FailBatch(ProxyRequestArgs e)
140
140
141
141
if ( errorStatus == HttpStatusCode . TooManyRequests )
142
142
{
143
- var retryAfterDate = DateTime . Now . AddSeconds ( retryAfterInSeconds ) ;
143
+ var retryAfterDate = DateTime . Now . AddSeconds ( _configuration . RetryAfterInSeconds ) ;
144
144
var requestUrl = ProxyUtils . GetAbsoluteRequestUrlFromBatch ( e . Session . HttpClient . Request . RequestUri , request . Url ) ;
145
145
var throttledRequests = e . GlobalData [ RetryAfterPlugin . ThrottledRequestsKey ] as List < ThrottlerInfo > ;
146
146
throttledRequests ? . Add ( new ThrottlerInfo ( GraphUtils . BuildThrottleKey ( requestUrl ) , ShouldThrottle , retryAfterDate ) ) ;
147
- response . Headers = new Dictionary < string , string > { { "Retry-After" , retryAfterInSeconds . ToString ( ) } } ;
147
+ response . Headers = new Dictionary < string , string > { { "Retry-After" , _configuration . RetryAfterInSeconds . ToString ( ) } } ;
148
148
}
149
149
150
150
responses . Add ( response ) ;
@@ -159,7 +159,7 @@ private void FailBatch(ProxyRequestArgs e)
159
159
private ThrottlingInfo ShouldThrottle ( Request request , string throttlingKey )
160
160
{
161
161
var throttleKeyForRequest = GraphUtils . BuildThrottleKey ( request ) ;
162
- return new ThrottlingInfo ( throttleKeyForRequest == throttlingKey ? retryAfterInSeconds : 0 , "Retry-After" ) ;
162
+ return new ThrottlingInfo ( throttleKeyForRequest == throttlingKey ? _configuration . RetryAfterInSeconds : 0 , "Retry-After" ) ;
163
163
}
164
164
165
165
private void UpdateProxyResponse ( ProxyRequestArgs e , HttpStatusCode errorStatus )
@@ -171,15 +171,15 @@ private void UpdateProxyResponse(ProxyRequestArgs e, HttpStatusCode errorStatus)
171
171
var headers = ProxyUtils . BuildGraphResponseHeaders ( request , requestId , requestDate ) ;
172
172
if ( errorStatus == HttpStatusCode . TooManyRequests )
173
173
{
174
- var retryAfterDate = DateTime . Now . AddSeconds ( retryAfterInSeconds ) ;
174
+ var retryAfterDate = DateTime . Now . AddSeconds ( _configuration . RetryAfterInSeconds ) ;
175
175
if ( ! e . GlobalData . ContainsKey ( RetryAfterPlugin . ThrottledRequestsKey ) )
176
176
{
177
177
e . GlobalData . Add ( RetryAfterPlugin . ThrottledRequestsKey , new List < ThrottlerInfo > ( ) ) ;
178
178
}
179
179
180
180
var throttledRequests = e . GlobalData [ RetryAfterPlugin . ThrottledRequestsKey ] as List < ThrottlerInfo > ;
181
181
throttledRequests ? . Add ( new ThrottlerInfo ( GraphUtils . BuildThrottleKey ( request ) , ShouldThrottle , retryAfterDate ) ) ;
182
- headers . Add ( new ( "Retry-After" , retryAfterInSeconds . ToString ( ) ) ) ;
182
+ headers . Add ( new ( "Retry-After" , _configuration . RetryAfterInSeconds . ToString ( ) ) ) ;
183
183
}
184
184
185
185
string body = JsonSerializer . Serialize ( new GraphErrorResponseBody (
0 commit comments