diff --git a/api/errors.go b/api/errors.go index c0115332a..869061418 100644 --- a/api/errors.go +++ b/api/errors.go @@ -1612,6 +1612,10 @@ func (e errorCodeMap) ToAPIErr(errCode ErrorCode) Error { return e.ToAPIErrWithErr(errCode, nil) } +func (e Error) Error() string { + return fmt.Sprintf("%s: %d => %s", e.Code, e.HTTPStatusCode, e.Description) +} + // GetAPIError provides API Error for input API error code. func GetAPIError(code ErrorCode) Error { if apiErr, ok := errorCodes[code]; ok { diff --git a/api/response.go b/api/response.go index 2abc58235..0e424623a 100644 --- a/api/response.go +++ b/api/response.go @@ -68,7 +68,11 @@ const ( hdrSSECopyKey = "X-Amz-Copy-Source-Server-Side-Encryption-Customer-Key" ) -var deploymentID, _ = uuid.NewRandom() +var ( + deploymentID, _ = uuid.NewRandom() + + xmlHeader = []byte(xml.Header) +) // Non exhaustive list of AWS S3 standard error responses - // http://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html @@ -181,6 +185,14 @@ func EncodeResponse(response interface{}) []byte { return bytesBuffer.Bytes() } +// EncodeToResponse encodes the response into ResponseWriter. +func EncodeToResponse(w http.ResponseWriter, response interface{}) error { + if _, err := w.Write(xmlHeader); err != nil { + return err + } + return xml.NewEncoder(w).Encode(response) +} + // WriteSuccessResponseXML writes success headers and response if any, // with content-type set to `application/xml`. func WriteSuccessResponseXML(w http.ResponseWriter, response []byte) {