Move ErrorCode logic to new errcode package

Make HTTP status codes match the ErrorCode by looking it up in the Descriptors

Signed-off-by: Doug Davis <dug@us.ibm.com>
This commit is contained in:
Doug Davis 2015-05-14 18:21:39 -07:00
parent 5f553b3cfc
commit f565d6abb7
16 changed files with 444 additions and 405 deletions

View file

@ -7,6 +7,7 @@ import (
"io/ioutil"
"net/http"
"github.com/docker/distribution/registry/api/errcode"
"github.com/docker/distribution/registry/api/v2"
)
@ -32,7 +33,7 @@ func (e *UnexpectedHTTPResponseError) Error() string {
}
func parseHTTPErrorResponse(r io.Reader) error {
var errors v2.Errors
var errors errcode.Errors
body, err := ioutil.ReadAll(r)
if err != nil {
return err
@ -51,7 +52,7 @@ func handleErrorResponse(resp *http.Response) error {
if resp.StatusCode == 401 {
err := parseHTTPErrorResponse(resp.Body)
if uErr, ok := err.(*UnexpectedHTTPResponseError); ok {
return &v2.Error{
return &errcode.Error{
Code: v2.ErrorCodeUnauthorized,
Message: "401 Unauthorized",
Detail: uErr.Response,