Skip to content

Commit

Permalink
change the "too old resource version" error from InternalError to 410…
Browse files Browse the repository at this point in the history
… Gone.
  • Loading branch information
Chao Xu committed Nov 25, 2015
1 parent e46f7e2 commit a470070
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/devel/api-conventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions pkg/api/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
5 changes: 5 additions & 0 deletions pkg/api/unversioned/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/watch_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a470070

Please sign in to comment.