From f596c744edf715d1ca9205042a07c8d73c0bea7f Mon Sep 17 00:00:00 2001 From: "Frederick F. Kautz IV" Date: Wed, 29 Apr 2015 17:21:23 -0700 Subject: [PATCH] Adding error message on connection limit met --- pkg/api/quota/conn_limit.go | 2 ++ pkg/api/quota/errors.go | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/pkg/api/quota/conn_limit.go b/pkg/api/quota/conn_limit.go index a281a537f..98cfb8b97 100644 --- a/pkg/api/quota/conn_limit.go +++ b/pkg/api/quota/conn_limit.go @@ -61,6 +61,8 @@ func (c *connLimit) ServeHTTP(w http.ResponseWriter, req *http.Request) { if c.TestAndAdd(longIP) { defer c.Remove(longIP) c.handler.ServeHTTP(w, req) + } else { + writeErrorResponse(w, req, ConnectionLimitExceeded, req.RequestURI) } } diff --git a/pkg/api/quota/errors.go b/pkg/api/quota/errors.go index d236aee79..93e1d21ad 100644 --- a/pkg/api/quota/errors.go +++ b/pkg/api/quota/errors.go @@ -47,6 +47,7 @@ const ( BandWidthQuotaExceeded BandWidthInsufficientToProceed SlowDown + ConnectionLimitExceeded ) // Golang http doesn't implement these @@ -89,6 +90,11 @@ var errorCodeResponse = map[int]Error{ Description: "Reduce your request rate.", HTTPStatusCode: StatusTooManyRequests, }, + ConnectionLimitExceeded: { + Code: "ConnectionLimit", + Description: "Connection Limit Met", + HTTPStatusCode: StatusTooManyRequests, + }, } // Write error response headers