Skip to content

Commit ea8bd07

Browse files
author
SESA826635
committed
fix(pingfed): add retries for swipe status
1 parent 44ed068 commit ea8bd07

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

pkg/provider/pingfed/pingfed.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,20 +230,34 @@ func (ac *Client) handleSwipe(ctx context.Context, doc *goquery.Document, _ *url
230230
if err != nil {
231231
return ctx, nil, err
232232
}
233-
233+
// Number of unrecoverable errors encountered successively
234+
errCount := 0
234235
for {
235-
time.Sleep(3 * time.Second)
236+
time.Sleep(1 * time.Second)
236237

237238
res, err := ac.client.Do(req)
238239
if err != nil {
239-
return ctx, nil, errors.Wrap(err, "error polling swipe status")
240+
errCount++
241+
if errCount > 3 {
242+
return ctx, nil, errors.Wrap(err, "error polling swipe status")
243+
} else {
244+
log.Printf("Error polling swipe status (errors: %d): %s", errCount, err)
245+
}
246+
240247
}
241248

242249
body, err := io.ReadAll(res.Body)
243250
if err != nil {
244-
return ctx, nil, errors.Wrap(err, "error parsing body from swipe status response")
251+
errCount++
252+
if errCount > 3 {
253+
return ctx, nil, errors.Wrap(err, "error parsing body from swipe status response")
254+
} else {
255+
log.Printf("Error reading swipe response status (errors: %d): %s", errCount, err)
256+
}
245257
}
246258

259+
// Once we reach this point, we have a full HTTP response
260+
errCount = 0
247261
resp := string(body)
248262

249263
pingfedMFAStatusResponse := gjson.Get(resp, "status").String()

0 commit comments

Comments
 (0)