Rename TryAgainLater status code to ServerTimeout

This commit is contained in:
Clayton Coleman 2015-02-12 12:24:34 -05:00
parent 3bc8f4e793
commit c24f4a24b4
10 changed files with 31 additions and 31 deletions

View File

@ -30,11 +30,11 @@ const (
StatusUnprocessableEntity = 422
StatusTooManyRequests = 429
// HTTP recommendations are for servers to define 5xx error codes
// for scenarios not covered by behavior. In this case, TryAgainLater
// for scenarios not covered by behavior. In this case, ServerTimeout
// is an indication that a transient server error has occured and the
// client *should* retry, with an optional Retry-After header to specify
// the back off window.
StatusTryAgainLater = 504
StatusServerTimeout = 504
)
// StatusError is an error intended for consumption by a REST API server; it can also be
@ -180,13 +180,13 @@ func NewMethodNotSupported(kind, action string) error {
}}
}
// NewTryAgainLater returns an error indicating the requested action could not be completed due to a
// NewServerTimeout returns an error indicating the requested action could not be completed due to a
// transient error, and the client should try again.
func NewTryAgainLater(kind, operation string) error {
func NewServerTimeout(kind, operation string) error {
return &StatusError{api.Status{
Status: api.StatusFailure,
Code: http.StatusInternalServerError,
Reason: api.StatusReasonTryAgainLater,
Reason: api.StatusReasonServerTimeout,
Details: &api.StatusDetails{
Kind: kind,
ID: operation,
@ -213,7 +213,7 @@ func NewInternalError(err error) error {
func NewTimeoutError(message string) error {
return &StatusError{api.Status{
Status: api.StatusFailure,
Code: StatusTryAgainLater,
Code: StatusServerTimeout,
Reason: api.StatusReasonTimeout,
Message: fmt.Sprintf("Timeout: %s", message),
}}
@ -256,10 +256,10 @@ func IsForbidden(err error) bool {
return reasonForError(err) == api.StatusReasonForbidden
}
// IsTryAgainLater determines if err is an error which indicates that the request needs to be retried
// IsServerTimeout determines if err is an error which indicates that the request needs to be retried
// by the client.
func IsTryAgainLater(err error) bool {
return reasonForError(err) == api.StatusReasonTryAgainLater
func IsServerTimeout(err error) bool {
return reasonForError(err) == api.StatusReasonServerTimeout
}
func reasonForError(err error) api.StatusReason {

View File

@ -46,8 +46,8 @@ func TestErrorNew(t *testing.T) {
if IsForbidden(err) {
t.Errorf("expected to not be %s", api.StatusReasonForbidden)
}
if IsTryAgainLater(err) {
t.Errorf("expected to not be %s", api.StatusReasonTryAgainLater)
if IsServerTimeout(err) {
t.Errorf("expected to not be %s", api.StatusReasonServerTimeout)
}
if IsMethodNotSupported(err) {
t.Errorf("expected to not be %s", api.StatusReasonMethodNotAllowed)
@ -68,8 +68,8 @@ func TestErrorNew(t *testing.T) {
if !IsForbidden(NewForbidden("test", "2", errors.New("reason"))) {
t.Errorf("expected to be %s", api.StatusReasonForbidden)
}
if !IsTryAgainLater(NewTryAgainLater("test", "reason")) {
t.Errorf("expected to be %s", api.StatusReasonTryAgainLater)
if !IsServerTimeout(NewServerTimeout("test", "reason")) {
t.Errorf("expected to be %s", api.StatusReasonServerTimeout)
}
if !IsMethodNotSupported(NewMethodNotSupported("foo", "delete")) {
t.Errorf("expected to be %s", api.StatusReasonMethodNotAllowed)

View File

@ -83,7 +83,7 @@ func CheckGeneratedNameError(strategy RESTCreateStrategy, err error, obj runtime
return err
}
return errors.NewTryAgainLater(kind, "POST")
return errors.NewServerTimeout(kind, "POST")
}
// objectMetaAndKind retrieves kind and ObjectMeta from a runtime object, or returns an error.

View File

@ -35,7 +35,7 @@ func TestCheckGeneratedNameError(t *testing.T) {
}
expect = errors.NewAlreadyExists("foo", "bar")
if err := CheckGeneratedNameError(Pods, expect, &api.Pod{ObjectMeta: api.ObjectMeta{GenerateName: "foo"}}); err == nil || !errors.IsTryAgainLater(err) {
if err := CheckGeneratedNameError(Pods, expect, &api.Pod{ObjectMeta: api.ObjectMeta{GenerateName: "foo"}}); err == nil || !errors.IsServerTimeout(err) {
t.Errorf("expected try again later error: %v", err)
}
}

View File

@ -66,7 +66,7 @@ func copyOrDie(obj runtime.Object) runtime.Object {
func (t *Tester) TestCreate(valid runtime.Object, invalid ...runtime.Object) {
t.TestCreateHasMetadata(copyOrDie(valid))
t.TestCreateGeneratesName(copyOrDie(valid))
t.TestCreateGeneratesNameReturnsTryAgain(copyOrDie(valid))
t.TestCreateGeneratesNameReturnsServerTimeout(copyOrDie(valid))
if t.clusterScope {
t.TestCreateRejectsNamespace(copyOrDie(valid))
} else {
@ -140,7 +140,7 @@ func (t *Tester) TestCreateGeneratesName(valid runtime.Object) {
}
}
func (t *Tester) TestCreateGeneratesNameReturnsTryAgain(valid runtime.Object) {
func (t *Tester) TestCreateGeneratesNameReturnsServerTimeout(valid runtime.Object) {
objectMeta, err := api.ObjectMetaFor(valid)
if err != nil {
t.Fatalf("object does not have ObjectMeta: %v\n%#v", err, valid)
@ -149,7 +149,7 @@ func (t *Tester) TestCreateGeneratesNameReturnsTryAgain(valid runtime.Object) {
objectMeta.GenerateName = "test-"
t.withStorageError(errors.NewAlreadyExists("kind", "thing"), func() {
_, err := t.storage.(apiserver.RESTCreater).Create(api.NewDefaultContext(), valid)
if err == nil || !errors.IsTryAgainLater(err) {
if err == nil || !errors.IsServerTimeout(err) {
t.Fatalf("Unexpected error: %v", err)
}
})

View File

@ -91,7 +91,7 @@ type ObjectMeta struct {
//
// If this field is specified, and Name is not present, the server will NOT return a 409 if the
// generated name exists - instead, it will either return 201 Created or 500 with Reason
// TryAgainLater indicating a unique name could not be found in the time allotted, and the client
// ServerTimeout indicating a unique name could not be found in the time allotted, and the client
// should retry (optionally after the time indicated in the Retry-After header).
GenerateName string `json:"generateName,omitempty"`
@ -999,7 +999,7 @@ const (
// Status code 422
StatusReasonInvalid StatusReason = "Invalid"
// StatusReasonTryAgainLater means the server can be reached and understood the request,
// StatusReasonServerTimeout means the server can be reached and understood the request,
// but cannot complete the action in a reasonable time. The client should retry the request.
// This is may be due to temporary server load or a transient communication issue with
// another server. Status code 500 is used because the HTTP spec provides no suitable
@ -1008,7 +1008,7 @@ const (
// "kind" string - the kind attribute of the resource being acted on.
// "id" string - the operation that is being attempted.
// Status code 500
StatusReasonTryAgainLater StatusReason = "TryAgainLater"
StatusReasonServerTimeout StatusReason = "ServerTimeout"
// StatusReasonTimeout means that the request could not be completed within the given time.
// Clients can get this response only when they specified a timeout param in the request.

View File

@ -343,7 +343,7 @@ type TypeMeta struct {
//
// If this field is specified, and Name is not present, the server will NOT return a 409 if the
// generated name exists - instead, it will either return 201 Created or 500 with Reason
// TryAgainLater indicating a unique name could not be found in the time allotted, and the client
// ServerTimeout indicating a unique name could not be found in the time allotted, and the client
// should retry (optionally after the time indicated in the Retry-After header).
GenerateName string `json:"generateName,omitempty" description:"an optional prefix to use to generate a unique name; has the same validation rules as name; optional, and is applied only name if is not specified"`
@ -804,7 +804,7 @@ const (
// Status code 409
StatusReasonConflict StatusReason = "Conflict"
// StatusReasonTryAgainLater means the server can be reached and understood the request,
// StatusReasonServerTimeout means the server can be reached and understood the request,
// but cannot complete the action in a reasonable time. The client should retry the request.
// This is may be due to temporary server load or a transient communication issue with
// another server. Status code 500 is used because the HTTP spec provides no suitable
@ -813,7 +813,7 @@ const (
// "kind" string - the kind attribute of the resource being acted on.
// "id" string - the operation that is being attempted.
// Status code 500
StatusReasonTryAgainLater StatusReason = "TryAgainLater"
StatusReasonServerTimeout StatusReason = "ServerTimeout"
)
// StatusCause provides more information about an api.Status failure, including

View File

@ -307,7 +307,7 @@ type TypeMeta struct {
//
// If this field is specified, and Name is not present, the server will NOT return a 409 if the
// generated name exists - instead, it will either return 201 Created or 500 with Reason
// TryAgainLater indicating a unique name could not be found in the time allotted, and the client
// ServerTimeout indicating a unique name could not be found in the time allotted, and the client
// should retry (optionally after the time indicated in the Retry-After header).
GenerateName string `json:"generateName,omitempty" description:"an optional prefix to use to generate a unique name; has the same validation rules as name; optional, and is applied only name if is not specified"`
@ -778,7 +778,7 @@ const (
// Status code 422
StatusReasonInvalid StatusReason = "Invalid"
// StatusReasonTryAgainLater means the server can be reached and understood the request,
// StatusReasonServerTimeout means the server can be reached and understood the request,
// but cannot complete the action in a reasonable time. The client should retry the request.
// This is may be due to temporary server load or a transient communication issue with
// another server. Status code 500 is used because the HTTP spec provides no suitable
@ -787,7 +787,7 @@ const (
// "kind" string - the kind attribute of the resource being acted on.
// "id" string - the operation that is being attempted.
// Status code 500
StatusReasonTryAgainLater StatusReason = "TryAgainLater"
StatusReasonServerTimeout StatusReason = "ServerTimeout"
)
// StatusCause provides more information about an api.Status failure, including

View File

@ -91,7 +91,7 @@ type ObjectMeta struct {
//
// If this field is specified, and Name is not present, the server will NOT return a 409 if the
// generated name exists - instead, it will either return 201 Created or 500 with Reason
// TryAgainLater indicating a unique name could not be found in the time allotted, and the client
// ServerTimeout indicating a unique name could not be found in the time allotted, and the client
// should retry (optionally after the time indicated in the Retry-After header).
GenerateName string `json:"generateName,omitempty" description:"an optional prefix to use to generate a unique name; has the same validation rules as name; optional, and is applied only name if is not specified"`
@ -1003,7 +1003,7 @@ const (
// Status code 422
StatusReasonInvalid StatusReason = "Invalid"
// StatusReasonTryAgainLater means the server can be reached and understood the request,
// StatusReasonServerTimeout means the server can be reached and understood the request,
// but cannot complete the action in a reasonable time. The client should retry the request.
// This is may be due to temporary server load or a transient communication issue with
// another server. Status code 500 is used because the HTTP spec provides no suitable
@ -1012,7 +1012,7 @@ const (
// "kind" string - the kind attribute of the resource being acted on.
// "id" string - the operation that is being attempted.
// Status code 500
StatusReasonTryAgainLater StatusReason = "TryAgainLater"
StatusReasonServerTimeout StatusReason = "ServerTimeout"
)
// StatusCause provides more information about an api.Status failure, including

View File

@ -1147,7 +1147,7 @@ func TestCreateTimeout(t *testing.T) {
simple := &Simple{Other: "foo"}
data, _ := codec.Encode(simple)
itemOut := expectApiStatus(t, "POST", server.URL+"/prefix/version/foo?timeout=4ms", data, apierrs.StatusTryAgainLater)
itemOut := expectApiStatus(t, "POST", server.URL+"/prefix/version/foo?timeout=4ms", data, apierrs.StatusServerTimeout)
if itemOut.Status != api.StatusFailure || itemOut.Reason != api.StatusReasonTimeout {
t.Errorf("Unexpected status %#v", itemOut)
}