1
0
mirror of https://github.com/rancher/norman.git synced 2025-08-31 14:51:57 +00:00

More initial dev

This commit is contained in:
Darren Shepherd
2017-11-10 21:44:02 -07:00
parent c06696a1e4
commit c8cab3f4f8
72 changed files with 5674 additions and 1211 deletions

View File

@@ -5,28 +5,38 @@ import (
)
var (
INVALID_DATE_FORMAT = ErrorCode("InvalidDateFormat")
INVALID_FORMAT = ErrorCode("InvalidFormat")
INVALID_REFERENCE = ErrorCode("InvalidReference")
NOT_NULLABLE = ErrorCode("NotNullable")
NOT_UNIQUE = ErrorCode("NotUnique")
MIN_LIMIT_EXCEEDED = ErrorCode("MinLimitExceeded")
MAX_LIMIT_EXCEEDED = ErrorCode("MaxLimitExceeded")
MIN_LENGTH_EXCEEDED = ErrorCode("MinLengthExceeded")
MAX_LENGTH_EXCEEDED = ErrorCode("MaxLengthExceeded")
INVALID_OPTION = ErrorCode("InvalidOption")
INVALID_CHARACTERS = ErrorCode("InvalidCharacters")
MISSING_REQUIRED = ErrorCode("MissingRequired")
INVALID_CSRF_TOKEN = ErrorCode("InvalidCSRFToken")
INVALID_ACTION = ErrorCode("InvalidAction")
INVALID_BODY_CONTENT = ErrorCode("InvalidBodyContent")
INVALID_TYPE = ErrorCode("InvalidType")
ACTION_NOT_AVAILABLE = ErrorCode("ActionNotAvailable")
INVALID_STATE = ErrorCode("InvalidState")
SERVER_ERROR = ErrorCode("ServerError")
INVALID_DATE_FORMAT = ErrorCode{"InvalidDateFormat", 422}
INVALID_FORMAT = ErrorCode{"InvalidFormat", 422}
INVALID_REFERENCE = ErrorCode{"InvalidReference", 422}
NOT_NULLABLE = ErrorCode{"NotNullable", 422}
NOT_UNIQUE = ErrorCode{"NotUnique", 422}
MIN_LIMIT_EXCEEDED = ErrorCode{"MinLimitExceeded", 422}
MAX_LIMIT_EXCEEDED = ErrorCode{"MaxLimitExceeded", 422}
MIN_LENGTH_EXCEEDED = ErrorCode{"MinLengthExceeded", 422}
MAX_LENGTH_EXCEEDED = ErrorCode{"MaxLengthExceeded", 422}
INVALID_OPTION = ErrorCode{"InvalidOption", 422}
INVALID_CHARACTERS = ErrorCode{"InvalidCharacters", 422}
MISSING_REQUIRED = ErrorCode{"MissingRequired", 422}
INVALID_CSRF_TOKEN = ErrorCode{"InvalidCSRFToken", 422}
INVALID_ACTION = ErrorCode{"InvalidAction", 422}
INVALID_BODY_CONTENT = ErrorCode{"InvalidBodyContent", 422}
INVALID_TYPE = ErrorCode{"InvalidType", 422}
ACTION_NOT_AVAILABLE = ErrorCode{"ActionNotAvailable", 404}
INVALID_STATE = ErrorCode{"InvalidState", 422}
SERVER_ERROR = ErrorCode{"ServerError", 500}
METHOD_NOT_ALLOWED = ErrorCode{"MethodNotAllow", 405}
NOT_FOUND = ErrorCode{"NotFound", 404}
)
type ErrorCode string
type ErrorCode struct {
code string
status int
}
func (e ErrorCode) String() string {
return fmt.Sprintf("%s %d", e.code, e.status)
}
type APIError struct {
code ErrorCode
@@ -52,7 +62,7 @@ func NewFieldAPIError(code ErrorCode, fieldName, message string) error {
func WrapFieldAPIError(err error, code ErrorCode, fieldName, message string) error {
return &APIError{
Cause: err,
Cause: err,
code: code,
message: message,
fieldName: fieldName,
@@ -68,5 +78,8 @@ func WrapAPIError(err error, code ErrorCode, message string) error {
}
func (a *APIError) Error() string {
if a.fieldName != "" {
return fmt.Sprintf("%s=%s: %s", a.fieldName, a.code, a.message)
}
return fmt.Sprintf("%s: %s", a.code, a.message)
}