Request body consumed on retry
Review this Go retry wrapper that retries a POST with a JSON body on transient failures.
What a strong answer looks like
Separate real bugs from style. Rank issues by severity, point at the root cause rather than the symptom, and suggest a concrete fix, specific and kind.
0:00 of about 16 min
Mark a line and say what kind of problem it is.0 findings
1func postWithRetry(url string, body io.Reader) (*http.Response, error) {
2 var lastErr error
3 for attempt := 0; attempt < 3; attempt++ {
4 req, _ := http.NewRequest("POST", url, body)
5 resp, err := http.DefaultClient.Do(req)
6 if err == nil && resp.StatusCode < 500 {
7 return resp, nil
8 }
9 lastErr = err
10 time.Sleep(time.Duration(attempt) * 200 * time.Millisecond)
11 }
12 return nil, lastErr
13}
Which questions mattered is sealed until you submit. Telling you now would just be handing over the edge cases.
Run or narrate your approach, then ask the coach.