Browse Source

s3tables test: improve error reporting on decoding failure

pull/8147/head
Chris Lu 3 weeks ago
parent
commit
9f1dd57939
  1. 9
      test/s3tables/client.go

9
test/s3tables/client.go

@ -4,6 +4,7 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"io"
"net/http" "net/http"
"github.com/seaweedfs/seaweedfs/weed/s3api/s3tables" "github.com/seaweedfs/seaweedfs/weed/s3api/s3tables"
@ -39,9 +40,13 @@ func (c *S3TablesClient) doRequestAndDecode(operation string, reqBody interface{
defer resp.Body.Close() defer resp.Body.Close()
if resp.StatusCode != http.StatusOK { 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 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) return fmt.Errorf("%s failed: %s - %s", operation, errResp.Type, errResp.Message)
} }

Loading…
Cancel
Save