Skip to content
This repository was archived by the owner on May 24, 2024. It is now read-only.

Commit ed9e9e0

Browse files
committed
add wait time to get organizations
1 parent a47298a commit ed9e9e0

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

affiliation/identity.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,26 @@ func (a *Affiliation) GetOrganizations(uuid, projectSlug string) *[]Enrollment {
157157

158158
endpoint := a.AffBaseURL + "/affiliation/" + url.PathEscape(projectSlug) + "/enrollments/" + uuid
159159

160-
_, res, err := a.httpClientProvider.Request(strings.TrimSpace(endpoint), "GET", headers, nil, nil)
161-
if err != nil {
162-
log.Println("GetOrganizations: Could not get the organizations: ", err)
160+
statusCode, res, err := a.httpClientProvider.Request(strings.TrimSpace(endpoint), "GET", headers, nil, nil)
161+
switch statusCode {
162+
case http.StatusBadRequest, http.StatusNotFound:
163+
log.Println("GetOrganizations: Could not get the enrollment: ", err)
163164
return nil
165+
case http.StatusOK:
166+
default:
167+
if err != nil {
168+
log.Println("GetOrganizations: Could not get the organizations: ", err)
169+
return nil
170+
}
171+
172+
var errMsg AffiliationsResponse
173+
err = json.Unmarshal(res, &errMsg)
174+
if err != nil || errMsg.Message != "" {
175+
log.Println("GetOrganizations: failed to get organizations: ", errMsg)
176+
}
177+
178+
time.Sleep(2 * time.Minute)
179+
return a.GetOrganizations(uuid, projectSlug)
164180
}
165181

166182
var response EnrollmentsResponse

0 commit comments

Comments
 (0)