Skip to content

Commit

Permalink
Merge pull request kubernetes#16628 from caesarxuchao/change-error-type
Browse files Browse the repository at this point in the history
Auto commit by PR queue bot
  • Loading branch information
k8s-merge-robot committed Dec 1, 2015
2 parents 945393c + a470070 commit 55f5e48
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 @@ -558,6 +558,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 @@ -157,6 +157,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 validation.ErrorList) 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 @@ -183,6 +183,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 @@ -277,7 +277,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 55f5e48

Please sign in to comment.