Dont return raw etcd errors

This commit is contained in:
nikhiljindal
2015-06-22 18:19:18 -07:00
parent 764d34d363
commit 4b7f7ce535
8 changed files with 59 additions and 22 deletions

View File

@@ -372,6 +372,11 @@ func IsServerTimeout(err error) bool {
return reasonForError(err) == api.StatusReasonServerTimeout
}
// IsInternalServerError determines if err is an error which indicates that there was an internal server error.
func IsInternalServerError(err error) bool {
return reasonForError(err) == api.StatusReasonInternalError
}
// IsUnexpectedServerError returns true if the server response was not in the expected API format,
// and may be the result of another HTTP actor.
func IsUnexpectedServerError(err error) bool {
@@ -409,6 +414,14 @@ func SuggestsClientDelay(err error) (int, bool) {
return 0, false
}
func IsAPIStatusError(err error) bool {
switch err.(type) {
case *StatusError:
return true
}
return false
}
func reasonForError(err error) api.StatusReason {
switch t := err.(type) {
case *StatusError:

View File

@@ -27,8 +27,10 @@ func InterpretGetError(err error, kind, name string) error {
switch {
case tools.IsEtcdNotFound(err):
return errors.NewNotFound(kind, name)
default:
case errors.IsAPIStatusError(err):
return err
default:
return errors.NewInternalError(err)
}
}
@@ -38,8 +40,10 @@ func InterpretCreateError(err error, kind, name string) error {
switch {
case tools.IsEtcdNodeExist(err):
return errors.NewAlreadyExists(kind, name)
default:
case errors.IsAPIStatusError(err):
return err
default:
return errors.NewInternalError(err)
}
}
@@ -49,8 +53,10 @@ func InterpretUpdateError(err error, kind, name string) error {
switch {
case tools.IsEtcdTestFailed(err), tools.IsEtcdNodeExist(err):
return errors.NewConflict(kind, name, err)
default:
case errors.IsAPIStatusError(err):
return err
default:
return errors.NewInternalError(err)
}
}
@@ -60,7 +66,9 @@ func InterpretDeleteError(err error, kind, name string) error {
switch {
case tools.IsEtcdNotFound(err):
return errors.NewNotFound(kind, name)
default:
case errors.IsAPIStatusError(err):
return err
default:
return errors.NewInternalError(err)
}
}