Skip to content

Commit fa1fb49

Browse files
authored
Adding retry when agreements missing (#267)
1 parent 85f283f commit fa1fb49

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

autocodesign/devportalclient/appstoreconnect/appstoreconnect.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"bytes"
88
"context"
99
"encoding/json"
10+
"errors"
1011
"fmt"
1112
"io"
1213
"net/http"
@@ -78,6 +79,16 @@ func NewRetryableHTTPClient() *http.Client {
7879
return true, nil
7980
}
8081

82+
if resp != nil && resp.StatusCode == http.StatusForbidden {
83+
var apiError *ErrorResponse
84+
if ok := errors.As(checkResponse(resp), &apiError); ok {
85+
if apiError.IsRequiredAgreementMissingOrExpired() {
86+
log.Warnf("Received error FORBIDDEN.REQUIRED_AGREEMENTS_MISSING_OR_EXPIRED (status 403), retrying request...")
87+
return true, nil
88+
}
89+
}
90+
}
91+
8192
if resp != nil && resp.StatusCode == http.StatusTooManyRequests {
8293
message := "Received HTTP 429 Too Many Requests"
8394
if rateLimit := resp.Header.Get("X-Rate-Limit"); rateLimit != "" {

autocodesign/devportalclient/appstoreconnect/error.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,22 @@ func (r ErrorResponse) IsCursorInvalid() bool {
4949
return false
5050
}
5151

52+
// IsRequiredAgreementMissingOrExpired ...
53+
func (r ErrorResponse) IsRequiredAgreementMissingOrExpired() bool {
54+
// status code: 403
55+
// code: FORBIDDEN.REQUIRED_AGREEMENTS_MISSING_OR_EXPIRED
56+
// title: A required agreement is missing or has expired.
57+
// detail: This request requires an in-effect agreement that has not been signed or has expired.
58+
59+
for _, err := range r.Errors {
60+
if err.Code == "FORBIDDEN.REQUIRED_AGREEMENTS_MISSING_OR_EXPIRED" {
61+
return true
62+
}
63+
}
64+
65+
return false
66+
}
67+
5268
// DeviceRegistrationError ...
5369
type DeviceRegistrationError struct {
5470
Reason string

0 commit comments

Comments
 (0)