Merge pull request #81265 from jfbai/replace-status-too-many-request

Replace self defined const StatusTooManyRequests with http.StatusTooM…
This commit is contained in:
Kubernetes Prow Robot 2019-08-19 15:09:31 -07:00 committed by GitHub
commit a6aea3fcd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -17,6 +17,7 @@ limitations under the License.
package eventratelimit
import (
"net/http"
"testing"
"time"
@ -516,7 +517,7 @@ func TestEventRateLimiting(t *testing.T) {
}
if err != nil {
statusErr, ok := err.(*errors.StatusError)
if ok && statusErr.ErrStatus.Code != errors.StatusTooManyRequests {
if ok && statusErr.ErrStatus.Code != http.StatusTooManyRequests {
t.Fatalf("%v: Request %v should yield a 429 response: %v", tc.name, rqIndex, err)
}
}

View File

@ -32,7 +32,9 @@ import (
const (
// StatusTooManyRequests means the server experienced too many requests within a
// given window and that the client must wait to perform the action again.
StatusTooManyRequests = 429
// DEPRECATED: please use http.StatusTooManyRequests, this will be removed in
// the future version.
StatusTooManyRequests = http.StatusTooManyRequests
)
// StatusError is an error intended for consumption by a REST API server; it can also be
@ -349,7 +351,7 @@ func NewTimeoutError(message string, retryAfterSeconds int) *StatusError {
func NewTooManyRequestsError(message string) *StatusError {
return &StatusError{metav1.Status{
Status: metav1.StatusFailure,
Code: StatusTooManyRequests,
Code: http.StatusTooManyRequests,
Reason: metav1.StatusReasonTooManyRequests,
Message: fmt.Sprintf("Too many requests: %s", message),
}}