Better convey duplicate name errors to client (#116)

Motivation: Creating duplicate resources currently results in a 500
error being displayed by the client, with no information about the true
nature of the failure.

Modifications:
* ResourceStore now converts any errors from the etcd client into
  fission errors, capturing the reason for the error in the case of a
  duplicate key (as ErrorNameExists)
* ErrorNameExists errors are signaled to the client with a
  409 (Conflict) HTTP status
* MakeErrorFromHTTP() now reads the body of the error response to
  retrieve the actual error message instead of using the HTTP status
  message
* the controller client now uses MakeErrorFromHTTP() to centralize
  status code -> error code mapping
* tests for all of the resources now check that duplicate resources are
  reported properly

Result: The client can now provide more context when a duplicate name is
given

related to #112
This commit is contained in:
Toby Crawley
2017-02-13 08:58:52 -08:00
committed by Soam Vasani
parent 99d6a95bc1
commit c8b5bb2972
4 changed files with 74 additions and 35 deletions
+1 -13
View File
@@ -80,19 +80,7 @@ func (c *Client) url(relativeUrl string) string {
func (c *Client) handleResponse(resp *http.Response) ([]byte, error) {
if resp.StatusCode != 200 {
var errCode int
switch resp.StatusCode {
case 403:
errCode = fission.ErrorNotAuthorized
case 404:
errCode = fission.ErrorNotFound
case 400:
errCode = fission.ErrorInvalidArgument
default:
errCode = fission.ErrorInternal
}
return nil, fission.MakeError(errCode,
fmt.Sprintf("HTTP error %v", resp.StatusCode))
return nil, fission.MakeErrorFromHTTP(resp)
}
body, err := ioutil.ReadAll(resp.Body)
return body, err