feat(gitea): read retry once on 5xx GET

This commit is contained in:
Mathias Bergqvist
2026-05-04 23:04:55 +02:00
parent 39dc22ec3a
commit fb473262ba
2 changed files with 45 additions and 1 deletions

View File

@@ -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)
}