Forráskód Böngészése

errdefs: remove "ErrAlreadyExists" because it's not an error

The `ErrAlreadyExists` error is used for 304 statuses, which
is not an error-condition, so should probably not be defined
as part of the errdefs package.

This patch removes the `ErrAlreadyExists` interface, and related
helpers, as it was currently not used.

Note that a 304 status can fulfil certain use-cases, but (refering
to https://www.codetinkerer.com/2015/12/04/choosing-an-http-status-code.html)
could probably be handled by a 200 OK, unless we want to perform
caching in the client.

If we do want to use 304 statuses, perhaps we need a separate class
of "errors" for this (?).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn 6 éve
szülő
commit
7d4b788381
5 módosított fájl, 1 hozzáadás és 42 törlés
  1. 0 5
      errdefs/defs.go
  2. 0 16
      errdefs/helpers.go
  3. 0 13
      errdefs/helpers_test.go
  4. 1 1
      errdefs/http_helpers.go
  5. 0 7
      errdefs/is.go

+ 0 - 5
errdefs/defs.go

@@ -43,11 +43,6 @@ type ErrNotModified interface {
 	NotModified()
 	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.
 // ErrNotImplemented signals that the requested action/feature is not implemented on the system as configured.
 type ErrNotImplemented interface {
 type ErrNotImplemented interface {
 	NotImplemented()
 	NotImplemented()

+ 0 - 16
errdefs/helpers.go

@@ -130,22 +130,6 @@ func NotModified(err error) error {
 	return errNotModified{err}
 	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 }
 type errNotImplemented struct{ error }
 
 
 func (errNotImplemented) NotImplemented() {}
 func (errNotImplemented) NotImplemented() {}

+ 0 - 13
errdefs/helpers_test.go

@@ -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) {
 func TestUnauthorized(t *testing.T) {
 	if IsUnauthorized(errTest) {
 	if IsUnauthorized(errTest) {
 		t.Fatalf("did not expect unauthorized error, got %T", errTest)
 		t.Fatalf("did not expect unauthorized error, got %T", errTest)

+ 1 - 1
errdefs/http_helpers.go

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

+ 0 - 7
errdefs/is.go

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