@@ -24,6 +24,7 @@ internal enum GraphRandomErrorFailMode
2424public class GraphRandomErrorConfiguration
2525{
2626 public List < int > AllowedErrors { get ; set ; } = new ( ) ;
27+ public int RetryAfterInSeconds { get ; set ; } = 5 ;
2728}
2829
2930public class GraphRandomErrorPlugin : BaseProxyPlugin
@@ -34,7 +35,6 @@ public class GraphRandomErrorPlugin : BaseProxyPlugin
3435
3536 public override string Name => nameof ( GraphRandomErrorPlugin ) ;
3637
37- private const int retryAfterInSeconds = 5 ;
3838 private readonly Dictionary < string , HttpStatusCode [ ] > _methodStatusCode = new ( )
3939 {
4040 {
@@ -140,11 +140,11 @@ private void FailBatch(ProxyRequestArgs e)
140140
141141 if ( errorStatus == HttpStatusCode . TooManyRequests )
142142 {
143- var retryAfterDate = DateTime . Now . AddSeconds ( retryAfterInSeconds ) ;
143+ var retryAfterDate = DateTime . Now . AddSeconds ( _configuration . RetryAfterInSeconds ) ;
144144 var requestUrl = ProxyUtils . GetAbsoluteRequestUrlFromBatch ( e . Session . HttpClient . Request . RequestUri , request . Url ) ;
145145 var throttledRequests = e . GlobalData [ RetryAfterPlugin . ThrottledRequestsKey ] as List < ThrottlerInfo > ;
146146 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 ( ) } } ;
148148 }
149149
150150 responses . Add ( response ) ;
@@ -159,7 +159,7 @@ private void FailBatch(ProxyRequestArgs e)
159159 private ThrottlingInfo ShouldThrottle ( Request request , string throttlingKey )
160160 {
161161 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" ) ;
163163 }
164164
165165 private void UpdateProxyResponse ( ProxyRequestArgs e , HttpStatusCode errorStatus )
@@ -171,15 +171,15 @@ private void UpdateProxyResponse(ProxyRequestArgs e, HttpStatusCode errorStatus)
171171 var headers = ProxyUtils . BuildGraphResponseHeaders ( request , requestId , requestDate ) ;
172172 if ( errorStatus == HttpStatusCode . TooManyRequests )
173173 {
174- var retryAfterDate = DateTime . Now . AddSeconds ( retryAfterInSeconds ) ;
174+ var retryAfterDate = DateTime . Now . AddSeconds ( _configuration . RetryAfterInSeconds ) ;
175175 if ( ! e . GlobalData . ContainsKey ( RetryAfterPlugin . ThrottledRequestsKey ) )
176176 {
177177 e . GlobalData . Add ( RetryAfterPlugin . ThrottledRequestsKey , new List < ThrottlerInfo > ( ) ) ;
178178 }
179179
180180 var throttledRequests = e . GlobalData [ RetryAfterPlugin . ThrottledRequestsKey ] as List < ThrottlerInfo > ;
181181 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 ( ) ) ) ;
183183 }
184184
185185 string body = JsonSerializer . Serialize ( new GraphErrorResponseBody (
0 commit comments