Naming of Reason constants is inconsistent

Changed ReasonType to StatusReason (to match the field) and
changed CauseReason to CauseType and renamed StatusCause.Reason to
Type.
This commit is contained in:
Clayton Coleman
2014-08-26 13:36:09 -04:00
parent 52923a1348
commit 0a841a49fd
7 changed files with 91 additions and 89 deletions

View File

@@ -40,7 +40,7 @@ func NewNotFoundErr(kind, name string) error {
return &apiServerError{api.Status{
Status: api.StatusFailure,
Code: http.StatusNotFound,
Reason: api.ReasonTypeNotFound,
Reason: api.StatusReasonNotFound,
Details: &api.StatusDetails{
Kind: kind,
ID: name,
@@ -54,7 +54,7 @@ func NewAlreadyExistsErr(kind, name string) error {
return &apiServerError{api.Status{
Status: api.StatusFailure,
Code: http.StatusConflict,
Reason: api.ReasonTypeAlreadyExists,
Reason: api.StatusReasonAlreadyExists,
Details: &api.StatusDetails{
Kind: kind,
ID: name,
@@ -68,7 +68,7 @@ func NewConflictErr(kind, name string, err error) error {
return &apiServerError{api.Status{
Status: api.StatusFailure,
Code: http.StatusConflict,
Reason: api.ReasonTypeConflict,
Reason: api.StatusReasonConflict,
Details: &api.StatusDetails{
Kind: kind,
ID: name,
@@ -83,7 +83,7 @@ func NewInvalidErr(kind, name string, errs errors.ErrorList) error {
for i := range errs {
if err, ok := errs[i].(errors.ValidationError); ok {
causes = append(causes, api.StatusCause{
Reason: api.CauseReasonType(err.Type),
Type: api.CauseType(err.Type),
Message: err.Error(),
Field: err.Field,
})
@@ -92,7 +92,7 @@ func NewInvalidErr(kind, name string, errs errors.ErrorList) error {
return &apiServerError{api.Status{
Status: api.StatusFailure,
Code: 422, // RFC 4918
Reason: api.ReasonTypeInvalid,
Reason: api.StatusReasonInvalid,
Details: &api.StatusDetails{
Kind: kind,
ID: name,
@@ -104,30 +104,30 @@ func NewInvalidErr(kind, name string, errs errors.ErrorList) error {
// IsNotFound returns true if the specified error was created by NewNotFoundErr
func IsNotFound(err error) bool {
return reasonForError(err) == api.ReasonTypeNotFound
return reasonForError(err) == api.StatusReasonNotFound
}
// IsAlreadyExists determines if the err is an error which indicates that a specified resource already exists.
func IsAlreadyExists(err error) bool {
return reasonForError(err) == api.ReasonTypeAlreadyExists
return reasonForError(err) == api.StatusReasonAlreadyExists
}
// IsConflict determines if the err is an error which indicates the provided update conflicts
func IsConflict(err error) bool {
return reasonForError(err) == api.ReasonTypeConflict
return reasonForError(err) == api.StatusReasonConflict
}
// IsInvalid determines if the err is an error which indicates the provided resource is not valid
func IsInvalid(err error) bool {
return reasonForError(err) == api.ReasonTypeInvalid
return reasonForError(err) == api.StatusReasonInvalid
}
func reasonForError(err error) api.ReasonType {
func reasonForError(err error) api.StatusReason {
switch t := err.(type) {
case *apiServerError:
return t.Status.Reason
}
return api.ReasonTypeUnknown
return api.StatusReasonUnknown
}
// errToAPIStatus converts an error to an api.Status object.
@@ -148,7 +148,7 @@ func errToAPIStatus(err error) *api.Status {
return &api.Status{
Status: api.StatusFailure,
Code: status,
Reason: api.ReasonTypeUnknown,
Reason: api.StatusReasonUnknown,
Message: err.Error(),
}
}