madmin: All APIs return ErrorResponse error type (#3632)

Avoid returning errors.New("Got HTTP Status") in all APIs
master
Anis Elleuch 8 years ago committed by Harshavardhana
parent 82373e3d50
commit c753b5dfeb
  1. 12
      pkg/madmin/heal-commands.go
  2. 5
      pkg/madmin/lock-commands.go
  3. 4
      pkg/madmin/service-commands.go

@ -19,7 +19,6 @@ package madmin
import ( import (
"encoding/xml" "encoding/xml"
"errors"
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
@ -207,7 +206,8 @@ func (adm *AdminClient) listObjectsHeal(bucket, prefix, marker, delimiter string
} }
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return toBeHealedObjects, errors.New("Got HTTP Status: " + resp.Status) return toBeHealedObjects, httpRespToErrorResponse(resp)
} }
err = xml.NewDecoder(resp.Body).Decode(&toBeHealedObjects) err = xml.NewDecoder(resp.Body).Decode(&toBeHealedObjects)
@ -309,7 +309,7 @@ func (adm *AdminClient) ListBucketsHeal() ([]BucketInfo, error) {
} }
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return []BucketInfo{}, errors.New("Got HTTP Status: " + resp.Status) return []BucketInfo{}, httpRespToErrorResponse(resp)
} }
var listBucketsHealResult ListBucketsHealResponse var listBucketsHealResult ListBucketsHealResponse
@ -364,7 +364,7 @@ func (adm *AdminClient) HealBucket(bucket string, dryrun bool) error {
} }
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return errors.New("Got HTTP Status: " + resp.Status) return httpRespToErrorResponse(resp)
} }
return nil return nil
@ -398,7 +398,7 @@ func (adm *AdminClient) HealObject(bucket, object string, dryrun bool) error {
} }
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return errors.New("Got HTTP Status: " + resp.Status) return httpRespToErrorResponse(resp)
} }
return nil return nil
@ -430,7 +430,7 @@ func (adm *AdminClient) HealFormat(dryrun bool) error {
} }
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return errors.New("Got HTTP Status: " + resp.Status) return httpRespToErrorResponse(resp)
} }
return nil return nil

@ -19,7 +19,6 @@ package madmin
import ( import (
"encoding/json" "encoding/json"
"errors"
"io" "io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@ -118,7 +117,7 @@ func (adm *AdminClient) ListLocks(bucket, prefix string, olderThan time.Duration
} }
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return nil, errors.New("Got HTTP Status: " + resp.Status) return nil, httpRespToErrorResponse(resp)
} }
return getLockInfos(resp.Body) return getLockInfos(resp.Body)
@ -150,7 +149,7 @@ func (adm *AdminClient) ClearLocks(bucket, prefix string, olderThan time.Duratio
} }
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return nil, errors.New("Got HTTP Status: " + resp.Status) return nil, httpRespToErrorResponse(resp)
} }
return getLockInfos(resp.Body) return getLockInfos(resp.Body)

@ -92,7 +92,7 @@ func (adm *AdminClient) ServiceStatus() (ServiceStatusMetadata, error) {
// Check response http status code // Check response http status code
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return ServiceStatusMetadata{}, errors.New("Got HTTP Status: " + resp.Status) return ServiceStatusMetadata{}, httpRespToErrorResponse(resp)
} }
// Unmarshal the server's json response // Unmarshal the server's json response
@ -129,7 +129,7 @@ func (adm *AdminClient) ServiceRestart() error {
} }
if resp.StatusCode != http.StatusOK { if resp.StatusCode != http.StatusOK {
return errors.New("Got HTTP Status: " + resp.Status) return httpRespToErrorResponse(resp)
} }
return nil return nil
} }
Loading…
Cancel
Save