Turn 409 into 500 Try Again Later when using generateName

If a client says they want the name to be generated, a 409 is
not appropriate (since they didn't specify a name). Instead, we
should return the next most appropriate error, which is a 5xx
error indicating the request failed but the client *should* try
again.  Since there is no 5xx error that exactly fits this purpose,
use 500 with StatusReasonTryAgainLater set.

This commit does not implement client retry on TryAgainLater, but
clients should retry up to a certain number of times.
This commit is contained in:
Clayton Coleman
2015-01-28 23:11:29 -05:00
parent e485dc93ca
commit 1588970ec4
21 changed files with 237 additions and 18 deletions

View File

@@ -174,6 +174,21 @@ func NewMethodNotSupported(kind, action string) error {
}}
}
// NewTryAgainLater 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 {
return &StatusError{api.Status{
Status: api.StatusFailure,
Code: http.StatusInternalServerError,
Reason: api.StatusReasonTryAgainLater,
Details: &api.StatusDetails{
Kind: kind,
ID: operation,
},
Message: fmt.Sprintf("The %s operation against %s could not be completed at this time, please try again.", operation, kind),
}}
}
// NewInternalError returns an error indicating the item is invalid and cannot be processed.
func NewInternalError(err error) error {
return &StatusError{api.Status{
@@ -218,6 +233,18 @@ func IsBadRequest(err error) bool {
return reasonForError(err) == api.StatusReasonBadRequest
}
// IsForbidden determines if err is an error which indicates that the request is forbidden and cannot
// be completed as requested.
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
// by the client.
func IsTryAgainLater(err error) bool {
return reasonForError(err) == api.StatusReasonTryAgainLater
}
func reasonForError(err error) api.StatusReason {
switch t := err.(type) {
case *StatusError: