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>
| ... | ... |
@@ -43,11 +43,6 @@ type ErrNotModified interface {
|
| 43 | 43 |
NotModified() |
| 44 | 44 |
} |
| 45 | 45 |
|
| 46 |
-// ErrAlreadyExists is a special case of ErrConflict which signals that the desired object already exists |
|
| 47 |
-type ErrAlreadyExists interface {
|
|
| 48 |
- AlreadyExists() |
|
| 49 |
-} |
|
| 50 |
- |
|
| 51 | 46 |
// ErrNotImplemented signals that the requested action/feature is not implemented on the system as configured. |
| 52 | 47 |
type ErrNotImplemented interface {
|
| 53 | 48 |
NotImplemented() |
| ... | ... |
@@ -130,22 +130,6 @@ func NotModified(err error) error {
|
| 130 | 130 |
return errNotModified{err}
|
| 131 | 131 |
} |
| 132 | 132 |
|
| 133 |
-type errAlreadyExists struct{ error }
|
|
| 134 |
- |
|
| 135 |
-func (errAlreadyExists) AlreadyExists() {}
|
|
| 136 |
- |
|
| 137 |
-func (e errAlreadyExists) Cause() error {
|
|
| 138 |
- return e.error |
|
| 139 |
-} |
|
| 140 |
- |
|
| 141 |
-// AlreadyExists is a helper to create an error of the class with the same name from any error type |
|
| 142 |
-func AlreadyExists(err error) error {
|
|
| 143 |
- if err == nil || IsAlreadyExists(err) {
|
|
| 144 |
- return err |
|
| 145 |
- } |
|
| 146 |
- return errAlreadyExists{err}
|
|
| 147 |
-} |
|
| 148 |
- |
|
| 149 | 133 |
type errNotImplemented struct{ error }
|
| 150 | 134 |
|
| 151 | 135 |
func (errNotImplemented) NotImplemented() {}
|
| ... | ... |
@@ -89,19 +89,6 @@ func TestNotModified(t *testing.T) {
|
| 89 | 89 |
} |
| 90 | 90 |
} |
| 91 | 91 |
|
| 92 |
-func TestAlreadyExists(t *testing.T) {
|
|
| 93 |
- if IsAlreadyExists(errTest) {
|
|
| 94 |
- t.Fatalf("did not expect already exists error, got %T", errTest)
|
|
| 95 |
- } |
|
| 96 |
- e := AlreadyExists(errTest) |
|
| 97 |
- if !IsAlreadyExists(e) {
|
|
| 98 |
- t.Fatalf("expected already exists error, got %T", e)
|
|
| 99 |
- } |
|
| 100 |
- if cause := e.(causal).Cause(); cause != errTest {
|
|
| 101 |
- t.Fatalf("causual should be errTest, got: %v", cause)
|
|
| 102 |
- } |
|
| 103 |
-} |
|
| 104 |
- |
|
| 105 | 92 |
func TestUnauthorized(t *testing.T) {
|
| 106 | 93 |
if IsUnauthorized(errTest) {
|
| 107 | 94 |
t.Fatalf("did not expect unauthorized error, got %T", errTest)
|
| ... | ... |
@@ -28,7 +28,7 @@ func GetHTTPErrorStatusCode(err error) int {
|
| 28 | 28 |
statusCode = http.StatusNotFound |
| 29 | 29 |
case IsInvalidParameter(err): |
| 30 | 30 |
statusCode = http.StatusBadRequest |
| 31 |
- case IsConflict(err) || IsAlreadyExists(err): |
|
| 31 |
+ case IsConflict(err): |
|
| 32 | 32 |
statusCode = http.StatusConflict |
| 33 | 33 |
case IsUnauthorized(err): |
| 34 | 34 |
statusCode = http.StatusUnauthorized |
| ... | ... |
@@ -15,7 +15,6 @@ func getImplementer(err error) error {
|
| 15 | 15 |
ErrForbidden, |
| 16 | 16 |
ErrSystem, |
| 17 | 17 |
ErrNotModified, |
| 18 |
- ErrAlreadyExists, |
|
| 19 | 18 |
ErrNotImplemented, |
| 20 | 19 |
ErrCancelled, |
| 21 | 20 |
ErrDeadline, |
| ... | ... |
@@ -77,12 +76,6 @@ func IsNotModified(err error) bool {
|
| 77 | 77 |
return ok |
| 78 | 78 |
} |
| 79 | 79 |
|
| 80 |
-// IsAlreadyExists returns if the passed in error is a AlreadyExists error |
|
| 81 |
-func IsAlreadyExists(err error) bool {
|
|
| 82 |
- _, ok := getImplementer(err).(ErrAlreadyExists) |
|
| 83 |
- return ok |
|
| 84 |
-} |
|
| 85 |
- |
|
| 86 | 80 |
// IsNotImplemented returns if the passed in error is an ErrNotImplemented |
| 87 | 81 |
func IsNotImplemented(err error) bool {
|
| 88 | 82 |
_, ok := getImplementer(err).(ErrNotImplemented) |