Merge pull request #38462 from thaJeztah/remove_non_error_from_errdefs

[RFC] errdefs: remove "ErrAlreadyExists" because it's not an error
This commit is contained in:
Tibor Vass 2019-03-21 17:19:07 -07:00 committed by GitHub
commit 2101a831df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 1 additions and 42 deletions

View file

@ -43,11 +43,6 @@ type ErrNotModified interface {
NotModified()
}
// ErrAlreadyExists is a special case of ErrConflict which signals that the desired object already exists
type ErrAlreadyExists interface {
AlreadyExists()
}
// ErrNotImplemented signals that the requested action/feature is not implemented on the system as configured.
type ErrNotImplemented interface {
NotImplemented()

View file

@ -130,22 +130,6 @@ func NotModified(err error) error {
return errNotModified{err}
}
type errAlreadyExists struct{ error }
func (errAlreadyExists) AlreadyExists() {}
func (e errAlreadyExists) Cause() error {
return e.error
}
// AlreadyExists is a helper to create an error of the class with the same name from any error type
func AlreadyExists(err error) error {
if err == nil || IsAlreadyExists(err) {
return err
}
return errAlreadyExists{err}
}
type errNotImplemented struct{ error }
func (errNotImplemented) NotImplemented() {}

View file

@ -89,19 +89,6 @@ func TestNotModified(t *testing.T) {
}
}
func TestAlreadyExists(t *testing.T) {
if IsAlreadyExists(errTest) {
t.Fatalf("did not expect already exists error, got %T", errTest)
}
e := AlreadyExists(errTest)
if !IsAlreadyExists(e) {
t.Fatalf("expected already exists error, got %T", e)
}
if cause := e.(causal).Cause(); cause != errTest {
t.Fatalf("causual should be errTest, got: %v", cause)
}
}
func TestUnauthorized(t *testing.T) {
if IsUnauthorized(errTest) {
t.Fatalf("did not expect unauthorized error, got %T", errTest)

View file

@ -28,7 +28,7 @@ func GetHTTPErrorStatusCode(err error) int {
statusCode = http.StatusNotFound
case IsInvalidParameter(err):
statusCode = http.StatusBadRequest
case IsConflict(err) || IsAlreadyExists(err):
case IsConflict(err):
statusCode = http.StatusConflict
case IsUnauthorized(err):
statusCode = http.StatusUnauthorized

View file

@ -15,7 +15,6 @@ func getImplementer(err error) error {
ErrForbidden,
ErrSystem,
ErrNotModified,
ErrAlreadyExists,
ErrNotImplemented,
ErrCancelled,
ErrDeadline,
@ -77,12 +76,6 @@ func IsNotModified(err error) bool {
return ok
}
// IsAlreadyExists returns if the passed in error is a AlreadyExists error
func IsAlreadyExists(err error) bool {
_, ok := getImplementer(err).(ErrAlreadyExists)
return ok
}
// IsNotImplemented returns if the passed in error is an ErrNotImplemented
func IsNotImplemented(err error) bool {
_, ok := getImplementer(err).(ErrNotImplemented)