Permalink
Browse files

retry-on-error

  • Loading branch information...
winterstein committed Aug 1, 2012
1 parent 9d64035 commit 76814f912f6fdd5e10bfc0074dfd166111e27a3a
Showing with 17 additions and 4 deletions.
  1. +17 −4 src/winterwell/jtwitter/Twitter.java
@@ -1666,9 +1666,22 @@ public Status getStatus(String username) throws TwitterException {
maxId = null;
// pageNumber = 1;
List<Status> msgs = new ArrayList<Status>();
- while (msgs.size() <= maxResults) {
- String json = http.getPage(url, var, authenticate);
- List<Status> nextpage = Status.getStatuses(json);
+ while (msgs.size() <= maxResults) {
+ List<Status> nextpage;
+ try {
+ String json = http.getPage(url, var, authenticate);
+ nextpage = Status.getStatuses(json);
+ } catch (TwitterException.Parsing pex) {
+ // Twitter bug, July 2012: malformed responses -- end is chopped off ~1 time in 20
+ // TODO remove when Twitter fix this!
+ if (http.isRetryOnError()) {
+ InternalUtils.sleep(250);
+ String json = http.getPage(url, var, authenticate);
+ nextpage = Status.getStatuses(json);
+ } else {
+ throw pex;
+ }
+ }
// This test replaces size<20. It requires an extra call to Twitter.
// But it fixes a bug whereby retweets aren't counted and can thus
// cause
@@ -1683,7 +1696,7 @@ public Status getStatus(String username) throws TwitterException {
msgs.addAll(dateFilter(nextpage));
// pageNumber++;
- var.put("max_id", maxId.toString());
+ var.put("max_id", maxId.toString());
}
return msgs;
}

0 comments on commit 76814f9

Please sign in to comment.