Enhance error responses for request limit and bring some code from api errors

~~~
mc: <ERROR> Failed to create bucket for URL [http://localhost:9000/newbucket-101]. Reason: [Reduce your request rate.].
~~~

Client sees proper errors now.
This commit is contained in:
Harshavardhana
2015-04-26 22:01:55 -07:00
parent 8a57006b36
commit 2d96d5ad57
4 changed files with 126 additions and 44 deletions

View File

@@ -17,11 +17,8 @@
package quota
import (
"bytes"
"encoding/binary"
"encoding/xml"
"net"
"net/http"
"sync"
"time"
)
@@ -95,24 +92,3 @@ func (p longIP) IptoUint32() (result uint32) {
}
return binary.BigEndian.Uint32(ip)
}
// copied from api, no cyclic deps allowed
// ErrorResponse - error response format
type ErrorResponse struct {
XMLName xml.Name `xml:"Error" json:"-"`
Code string
Message string
Resource string
RequestID string
HostID string
}
func writeError(w http.ResponseWriter, req *http.Request, errorResponse ErrorResponse, status int) {
var buf bytes.Buffer
encoder := xml.NewEncoder(&buf)
w.WriteHeader(status)
encoder.Encode(errorResponse)
encoder.Flush()
w.Write(buf.Bytes())
}