Permalink
Browse files

Handle user daily rate limit errors coming back from Twitter in 403 r…

…esponses. SOCIALTW-27
  • Loading branch information...
1 parent 53753a2 commit 776d576a2ced34b2d99922cff02b477cf0652b30 Craig Walls committed Jan 18, 2012
@@ -67,7 +67,7 @@ public void handleError(ClientHttpResponse response) throws IOException {
}
private void handleClientErrors(ClientHttpResponse response) throws IOException {
- HttpStatus statusCode = response.getStatusCode();
+ HttpStatus statusCode = response.getStatusCode();
Map<String, Object> errorMap = extractErrorDetailsFromResponse(response);
if (errorMap == null) {
return; // unexpected error body, can't be handled here
@@ -106,6 +106,8 @@ private void handleClientErrors(ClientHttpResponse response) throws IOException
throw new MessageTooLongException(errorText);
} else if (errorText.equals(INVALID_MESSAGE_RECIPIENT_TEXT)) {
throw new InvalidMessageRecipientException(errorText);
+ } else if (errorText.equals(DAILY_RATE_LIMIT_TEXT)) {
+ throw new RateLimitExceededException();
} else {
throw new OperationNotPermittedException(errorText);
}
@@ -140,6 +142,8 @@ private void handleServerErrors(HttpStatus statusCode) throws IOException {
private static final String STATUS_TOO_LONG_TEXT = "Status is over 140 characters.";
private static final String MESSAGE_TOO_LONG_TEXT = "The text of your direct message is over 140 characters";
private static final String DUPLICATE_STATUS_TEXT = "Status is a duplicate.";
+ private static final String DAILY_RATE_LIMIT_TEXT = "User is over daily status update limit.";
+
private static final int ENHANCE_YOUR_CALM = 420;
}
@@ -138,4 +138,13 @@ public void unparseableSuccessResponse() {
twitter.timelineOperations().getHomeTimeline();
}
+ @Test(expected = RateLimitExceededException.class)
+ public void dailyStatusLimitExceeded() {
+ mockServer.expect(requestTo("https://api.twitter.com/1/statuses/update.json"))
+ .andExpect(method(POST))
+ .andExpect(body("status=Some+message"))
+ .andRespond(withResponse("{\"error\":\"User is over daily status update limit.\", \"request\":\"/1/statuses/update.json\"}", responseHeaders, HttpStatus.FORBIDDEN, ""));
+ twitter.timelineOperations().updateStatus("Some message");
+ }
+
}

0 comments on commit 776d576

Please sign in to comment.