From a4700707b386447b85ed112c195efd5648ae999f Mon Sep 17 00:00:00 2001 From: Chao Xu Date: Fri, 30 Oct 2015 15:32:44 -0700 Subject: [PATCH] change the "too old resource version" error from InternalError to 410 Gone. --- docs/devel/api-conventions.md | 4 ++++ pkg/api/errors/errors.go | 10 ++++++++++ pkg/api/unversioned/types.go | 5 +++++ pkg/storage/watch_cache.go | 2 +- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/docs/devel/api-conventions.md b/docs/devel/api-conventions.md index cf389231a3e..9a71fe1c753 100644 --- a/docs/devel/api-conventions.md +++ b/docs/devel/api-conventions.md @@ -547,6 +547,10 @@ The following HTTP status codes may be returned by the API. * * If updating an existing resource: * See `Conflict` from the `status` response section below on how to retrieve more information about the nature of the conflict. * GET and compare the fields in the pre-existing object, merge changes (if still valid according to preconditions), and retry with the updated request (including `ResourceVersion`). +* `410 StatusGone` + * Indicates that the item is no longer available at the server and no forwarding address is known. + * Suggested client recovery behavior + * Do not retry. Fix the request. * `422 StatusUnprocessableEntity` * Indicates that the requested create or update operation cannot be completed due to invalid data provided as part of the request. * Suggested client recovery behavior diff --git a/pkg/api/errors/errors.go b/pkg/api/errors/errors.go index 8f1fdb965b2..43c3e3ef73f 100644 --- a/pkg/api/errors/errors.go +++ b/pkg/api/errors/errors.go @@ -158,6 +158,16 @@ func NewConflict(kind, name string, err error) error { }} } +// NewGone returns an error indicating the item no longer available at the server and no forwarding address is known. +func NewGone(message string) error { + return &StatusError{unversioned.Status{ + Status: unversioned.StatusFailure, + Code: http.StatusGone, + Reason: unversioned.StatusReasonGone, + Message: message, + }} +} + // NewInvalid returns an error indicating the item is invalid and cannot be processed. func NewInvalid(kind, name string, errs fielderrors.ValidationErrorList) error { causes := make([]unversioned.StatusCause, 0, len(errs)) diff --git a/pkg/api/unversioned/types.go b/pkg/api/unversioned/types.go index c90bf296571..eeab163fc87 100644 --- a/pkg/api/unversioned/types.go +++ b/pkg/api/unversioned/types.go @@ -162,6 +162,11 @@ const ( // Status code 409 StatusReasonConflict StatusReason = "Conflict" + // StatusReasonGone means the item is no longer available at the server and no + // forwarding address is known. + // Status code 410 + StatusReasonGone StatusReason = "Gone" + // StatusReasonInvalid means the requested create or update operation cannot be // completed due to invalid data provided as part of the request. The client may // need to alter the request. When set, the client may use the StatusDetails diff --git a/pkg/storage/watch_cache.go b/pkg/storage/watch_cache.go index 1b376feec1a..475f8b71f38 100644 --- a/pkg/storage/watch_cache.go +++ b/pkg/storage/watch_cache.go @@ -266,7 +266,7 @@ func (w *watchCache) GetAllEventsSinceThreadUnsafe(resourceVersion uint64) ([]wa return result, nil } if resourceVersion < oldest { - return nil, errors.NewInternalError(fmt.Errorf("too old resource version: %d (%d)", resourceVersion, oldest)) + return nil, errors.NewGone(fmt.Sprintf("too old resource version: %d (%d)", resourceVersion, oldest)) } // Binary seatch the smallest index at which resourceVersion is not smaller than