fix(retry): retry transient edge answers centrally, fix stale task test (#57)
Release Please / Release Please (push) Skipped
Release / GoReleaser (push) Skipped
Tests / Secret scan (gitleaks) (push) Skipped
Tests / Test (Go 1.25) (push) Skipped
Tests / Test (Go stable) (push) Skipped
Tests / Secret scan (gitleaks) (pull_request) Successful in 4s
Tests / Test (Go 1.25) (pull_request) Successful in 21s
Tests / Test (Go stable) (pull_request) Successful in 21s

- Route HTTP helpers (getJSON/formRequest/deleteReq/postJSON/putJSON/
  multipart upload), Query and AuthenticateContext/ensureToken through the
  deterministic 429/502/503/504 retry (retryRaw), so the integration suite
  no longer fails on the shared openresty rate limit under parallel runs.
- Fix stale cmd/office/fetch integration test: loader.TaskFields was
  replaced by loader.DetailForm (broke go vet -tags=integration).
- Add unit tests for Transient/DoRetry.
This commit is contained in:
2026-09-16 21:32:14 +00:00
parent 8a17a32269
commit d6b8eb7777
7 changed files with 169 additions and 18 deletions
+15 -1
View File
@@ -8,6 +8,7 @@ package onlyoffice
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
@@ -49,6 +50,12 @@ func (r Request) GetMethod() string {
// - If request.NoAuth is true then no token is fetched — the caller is
// responsible for authenticating requests (used internally by Auth()).
func (c *Client) Query(request Request, result interface{}) error {
return DoRetry(context.Background(), DefaultRetryPolicy(), func() error {
return c.queryOnce(request, result)
})
}
func (c *Client) queryOnce(request Request, result interface{}) error {
url := c.credentials.Url + request.Uri
if request.Params != nil {
@@ -90,10 +97,17 @@ func (c *Client) Query(request Request, result interface{}) error {
}
defer resp.Body.Close()
raw, err := io.ReadAll(resp.Body)
if err != nil {
return err
}
if resp.StatusCode >= 400 {
return fmt.Errorf("%s %s: %d %s", request.GetMethod(), request.Uri, resp.StatusCode, truncate(string(raw), 400))
}
if result == nil {
return nil
}
return json.NewDecoder(resp.Body).Decode(result)
return json.Unmarshal(raw, result)
}
// requestBodyReader normalises Query() body input into an io.Reader.