s3tables test: improve error reporting on decoding failure

This commit is contained in:
Chris Lu
2026-01-28 12:30:30 -08:00
parent 1f70d82170
commit 9f1dd57939

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3tables"
@@ -39,9 +40,13 @@ func (c *S3TablesClient) doRequestAndDecode(operation string, reqBody interface{
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
bodyBytes, readErr := io.ReadAll(resp.Body)
if readErr != nil {
return fmt.Errorf("%s failed with status %d and could not read error response body: %v", operation, resp.StatusCode, readErr)
}
var errResp s3tables.S3TablesError
if err := json.NewDecoder(resp.Body).Decode(&errResp); err != nil {
return fmt.Errorf("%s failed with status %d and could not decode error response: %v", operation, resp.StatusCode, err)
if err := json.Unmarshal(bodyBytes, &errResp); err != nil {
return fmt.Errorf("%s failed with status %d, could not decode error response: %v. Body: %s", operation, resp.StatusCode, err, string(bodyBytes))
}
return fmt.Errorf("%s failed: %s - %s", operation, errResp.Type, errResp.Message)
}