Merge "RestApiServlet: Introduce constant for HTTP 429 code"

This commit is contained in:
Edwin Kempin
2019-09-26 06:22:40 +00:00
committed by Gerrit Code Review
2 changed files with 10 additions and 2 deletions

View File

@@ -210,6 +210,7 @@ public class RestApiServlet extends HttpServlet {
public static final String XD_AUTHORIZATION = "access_token";
public static final String XD_CONTENT_TYPE = "$ct";
public static final String XD_METHOD = "$m";
public static final int SC_TOO_MANY_REQUESTS = 429;
private static final int HEAP_EST_SIZE = 10 * 8 * 1024; // Presize 10 blocks.
private static final String PLAIN_TEXT = "text/plain";
@@ -651,7 +652,13 @@ public class RestApiServlet extends HttpServlet {
}
} catch (QuotaException e) {
responseBytes =
replyError(req, res, status = 429, messageOr(e, "Quota limit reached"), e.caching(), e);
replyError(
req,
res,
status = SC_TOO_MANY_REQUESTS,
messageOr(e, "Quota limit reached"),
e.caching(),
e);
} catch (Exception e) {
status = SC_INTERNAL_SERVER_ERROR;
responseBytes = handleException(e, req, res);

View File

@@ -14,6 +14,7 @@
package com.google.gerrit.acceptance.server.quota;
import static com.google.gerrit.httpd.restapi.RestApiServlet.SC_TOO_MANY_REQUESTS;
import static org.mockito.Mockito.clearInvocations;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -119,7 +120,7 @@ public class RestApiQuotaIT extends AbstractDaemonTest {
public void outOfQuotaReturnsError() throws Exception {
when(quotaBackendWithUser.requestToken("/restapi/config/version:GET"))
.thenReturn(singletonAggregation(QuotaResponse.error("no quota")));
adminRestSession.get("/config/server/version").assertStatus(429);
adminRestSession.get("/config/server/version").assertStatus(SC_TOO_MANY_REQUESTS);
verify(quotaBackendWithUser).requestToken("/restapi/config/version:GET");
}