mirror of
https://github.com/project-zot/zot.git
synced 2024-12-16 21:56:37 -05:00
errors: compliance requires error codes to be string enum constants.
This commit is contained in:
parent
8803c5f99b
commit
48fb4967a2
1 changed files with 36 additions and 3 deletions
|
@ -1,9 +1,11 @@
|
|||
package api
|
||||
|
||||
import "github.com/anuvu/zot/errors"
|
||||
import (
|
||||
"github.com/anuvu/zot/errors"
|
||||
)
|
||||
|
||||
type Error struct {
|
||||
Code ErrorCode `json:"code"`
|
||||
Code string `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Description string `json:"description"`
|
||||
Detail interface{} `json:"detail,omitempty"`
|
||||
|
@ -34,6 +36,27 @@ const (
|
|||
UNSUPPORTED
|
||||
)
|
||||
|
||||
func (e ErrorCode) String() string {
|
||||
m := map[ErrorCode]string{
|
||||
BLOB_UNKNOWN: "BLOB_UNKNOWN",
|
||||
BLOB_UPLOAD_INVALID: "BLOB_UPLOAD_INVALID",
|
||||
BLOB_UPLOAD_UNKNOWN: "BLOB_UPLOAD_UNKNOWN",
|
||||
DIGEST_INVALID: "DIGEST_INVALID",
|
||||
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",
|
||||
}
|
||||
return m[e]
|
||||
}
|
||||
|
||||
func NewError(code ErrorCode, detail ...interface{}) Error {
|
||||
var errMap = map[ErrorCode]Error{
|
||||
BLOB_UNKNOWN: {
|
||||
|
@ -135,8 +158,18 @@ func NewError(code ErrorCode, detail ...interface{}) Error {
|
|||
panic(errors.ErrUnknownCode)
|
||||
}
|
||||
|
||||
e.Code = code
|
||||
e.Code = code.String()
|
||||
e.Detail = detail
|
||||
|
||||
return e
|
||||
}
|
||||
|
||||
func NewErrorList(errors ...Error) ErrorList {
|
||||
el := make([]*Error, 0)
|
||||
|
||||
for _, e := range errors {
|
||||
el = append(el, &e)
|
||||
}
|
||||
|
||||
return ErrorList{el}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue