Replace self defined const StatusTooManyRequests with http.StatusTooManyRequests.

This commit is contained in:
Jianfei Bai 2019-08-11 21:05:49 +08:00
parent 46e58df837
commit 07077a8aa5
2 changed files with 5 additions and 2 deletions

View File

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

View File

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