Compare commits

...

1 Commits

Author SHA1 Message Date
Abhishek Pandey
f9bf9bc1aa Add 400 retry 2023-12-29 17:18:11 -08:00
2 changed files with 13 additions and 3 deletions

View File

@ -52,7 +52,8 @@ const (
// This error occurs when an attempt is made to create a folder that has
// the same name as another folder in the same parent. Such duplicate folder
// names are not allowed by graph.
folderExists errorCode = "ErrorFolderExists"
folderExists errorCode = "ErrorFolderExists"
invalidRequest errorCode = "invalidRequest"
// Some datacenters are returning this when we try to get the inbox of a user
// that doesn't exist.
invalidUser errorCode = "ErrorInvalidUser"
@ -140,6 +141,14 @@ var (
ErrTokenExpired = clues.New("jwt token expired")
)
// IsErrInvalidRequest is to retry transient graph 400 errors with odata error code
// set to invalidRequest.
func IsErrInvalidRequest(err error, resp *http.Response) bool {
return resp != nil &&
resp.StatusCode == http.StatusBadRequest &&
parseODataErr(err).hasErrorCode(err, invalidRequest)
}
func IsErrApplicationThrottled(err error) bool {
return errors.Is(err, ErrApplicationThrottled) ||
parseODataErr(err).hasErrorCode(err, applicationThrottled)

View File

@ -161,7 +161,8 @@ func (mw RetryMiddleware) Intercept(
retriable := IsErrTimeout(err) ||
IsErrConnectionReset(err) ||
mw.isRetriableRespCode(ctx, resp)
mw.isRetriableRespCode(ctx, resp) ||
IsErrInvalidRequest(err, resp)
if !retriable {
return resp, stackReq(ctx, req, resp, err).OrNil()
@ -206,7 +207,7 @@ func (mw RetryMiddleware) retryRequest(
// 1, there was a prior error OR the status code match retriable conditions.
// 3, the request method is retriable.
// 4, we haven't already hit maximum retries.
shouldRetry := (priorErr != nil || mw.isRetriableRespCode(ctx, resp)) &&
shouldRetry := (priorErr != nil || mw.isRetriableRespCode(ctx, resp) || IsErrInvalidRequest(priorErr, resp)) &&
mw.isRetriableRequest(req) &&
executionCount < mw.MaxRetries