Test atomic PUTs, and make them work.
Improve apiserver/logger.go's interface (it's pretty cool now). Improve apiserver's error reporting to clients. Improve client's handling of errors from apiserver. Make failed PUTs return 409 (conflict)-- http status codes are amazingly well defined for what we're doing!
This commit is contained in:
@@ -100,16 +100,27 @@ func (c *Client) doRequest(request *http.Request) ([]byte, error) {
|
||||
if err != nil {
|
||||
return body, err
|
||||
}
|
||||
if response.StatusCode < http.StatusOK || response.StatusCode > http.StatusPartialContent {
|
||||
|
||||
// Did the server give us a status response?
|
||||
isStatusResponse := false
|
||||
var status api.Status
|
||||
if err := api.DecodeInto(body, &status); err == nil && status.Status != "" {
|
||||
isStatusResponse = true
|
||||
}
|
||||
|
||||
switch {
|
||||
case response.StatusCode == http.StatusConflict:
|
||||
// Return error given by server, if there was one.
|
||||
if isStatusResponse {
|
||||
return nil, &StatusErr{status}
|
||||
}
|
||||
fallthrough
|
||||
case response.StatusCode < http.StatusOK || response.StatusCode > http.StatusPartialContent:
|
||||
return nil, fmt.Errorf("request [%#v] failed (%d) %s: %s", request, response.StatusCode, response.Status, string(body))
|
||||
}
|
||||
|
||||
// If the server gave us a status back, look at what it was.
|
||||
var status api.Status
|
||||
if err := api.DecodeInto(body, &status); err == nil && status.Status != "" {
|
||||
if status.Status == api.StatusSuccess {
|
||||
return body, nil
|
||||
}
|
||||
if isStatusResponse && status.Status != api.StatusSuccess {
|
||||
// "Working" requests need to be handled specially.
|
||||
// "Failed" requests are clearly just an error and it makes sense to return them as such.
|
||||
return nil, &StatusErr{status}
|
||||
|
Reference in New Issue
Block a user