feat(gitea): read retry once on 5xx GET
This commit is contained in:
@@ -22,7 +22,7 @@ func NewClient(baseURL, token string) *Client {
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) do(ctx context.Context, method, path string, body []byte) ([]byte, int, error) {
|
||||
func (c *Client) doOnce(ctx context.Context, method, path string, body []byte) ([]byte, int, error) {
|
||||
var reader io.Reader
|
||||
if body != nil {
|
||||
reader = bytes.NewReader(body)
|
||||
@@ -48,6 +48,15 @@ func (c *Client) do(ctx context.Context, method, path string, body []byte) ([]by
|
||||
return b, resp.StatusCode, err
|
||||
}
|
||||
|
||||
func (c *Client) do(ctx context.Context, method, path string, body []byte) ([]byte, int, error) {
|
||||
b, status, err := c.doOnce(ctx, method, path, body)
|
||||
if err == nil && method == http.MethodGet && status >= 500 && status < 600 {
|
||||
time.Sleep(250 * time.Millisecond)
|
||||
return c.doOnce(ctx, method, path, body)
|
||||
}
|
||||
return b, status, err
|
||||
}
|
||||
|
||||
func (c *Client) GetJSON(ctx context.Context, path string) ([]byte, int, error) {
|
||||
return c.do(ctx, http.MethodGet, path, nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user