0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2025-03-11 02:17:43 -05:00

fix: errors returned by zot should match the dist-spec errors (#1868)

Signed-off-by: Alexei Dodon <adodon@cisco.com>
This commit is contained in:
Alexei Dodon 2023-09-29 23:45:19 +03:00 committed by GitHub
parent 56e3580687
commit 75085dcff5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 26 deletions

View file

@ -26,15 +26,13 @@ const (
MANIFEST_BLOB_UNKNOWN
MANIFEST_INVALID
MANIFEST_UNKNOWN
MANIFEST_UNVERIFIED
NAME_INVALID
NAME_UNKNOWN
SIZE_INVALID
TAG_INVALID
UNAUTHORIZED
DENIED
UNSUPPORTED
INVALID_INDEX
TOOMANYREQUESTS
)
func (e ErrorCode) String() string {
@ -46,15 +44,13 @@ func (e ErrorCode) String() string {
MANIFEST_BLOB_UNKNOWN: "MANIFEST_BLOB_UNKNOWN",
MANIFEST_INVALID: "MANIFEST_INVALID",
MANIFEST_UNKNOWN: "MANIFEST_UNKNOWN",
MANIFEST_UNVERIFIED: "MANIFEST_UNVERIFIED",
NAME_INVALID: "NAME_INVALID",
NAME_UNKNOWN: "NAME_UNKNOWN",
SIZE_INVALID: "SIZE_INVALID",
TAG_INVALID: "TAG_INVALID",
UNAUTHORIZED: "UNAUTHORIZED",
DENIED: "DENIED",
UNSUPPORTED: "UNSUPPORTED",
INVALID_INDEX: "INVALID_INDEX",
TOOMANYREQUESTS: "TOOMANYREQUESTS",
}
return errMap[e]
@ -105,12 +101,6 @@ func NewError(code ErrorCode) *Error {
"and tag is unknown to the repository.",
},
MANIFEST_UNVERIFIED: {
Message: "manifest failed signature verification",
Description: "During manifest upload, if the manifest fails signature " +
"verification, this error will be returned.",
},
NAME_INVALID: {
Message: "invalid repository name",
Description: "Invalid repository name encountered either during manifest " +
@ -128,12 +118,6 @@ func NewError(code ErrorCode) *Error {
"the uploaded content. If they do not match, this error will be returned.",
},
TAG_INVALID: {
Message: "manifest tag did not match URI",
Description: "During a manifest upload, if the tag in the manifest does " +
"not match the uri tag, this error will be returned.",
},
UNAUTHORIZED: {
Message: "authentication required",
Description: "The access controller was unable to authenticate the client." +
@ -147,14 +131,14 @@ func NewError(code ErrorCode) *Error {
},
UNSUPPORTED: {
Message: "The operation is unsupported.",
Message: "the operation is unsupported",
Description: "The operation was unsupported due to a missing " +
"implementation or invalid set of parameters.",
},
INVALID_INDEX: {
Message: "Invalid format of index.json file of the repo",
Description: "index.json file does not contain data in json format",
TOOMANYREQUESTS: {
Message: "too many requests",
Description: "When a user or users has sent too many requests to the server within a given amount of time.",
},
}

View file

@ -698,10 +698,6 @@ func (rh *RouteHandler) UpdateManifest(response http.ResponseWriter, request *ht
details["blob"] = digest.String()
e := apiErr.NewError(apiErr.BLOB_UNKNOWN).AddDetail(details)
zcommon.WriteJSON(response, http.StatusBadRequest, apiErr.NewErrorList(e))
} else if errors.Is(err, zerr.ErrRepoBadVersion) {
details["name"] = name
e := apiErr.NewError(apiErr.INVALID_INDEX).AddDetail(details)
zcommon.WriteJSON(response, http.StatusInternalServerError, apiErr.NewErrorList(e))
} else if errors.Is(err, zerr.ErrImageLintAnnotations) {
details["reference"] = reference
e := apiErr.NewError(apiErr.MANIFEST_INVALID).AddDetail(details)