Fixed Nullpointer Exception on saveGeneralData
Increased RetryTimes Decreased Activities per_page value while getting the activities
This commit is contained in:
@@ -36,9 +36,9 @@ public class Main
|
||||
{
|
||||
public static final String baseUrl = "https://www.strava.com/api/v3/";
|
||||
public static final String tokenUrl = "https://www.strava.com/api/v3/oauth/token";
|
||||
private static final int retryTimes = 20;
|
||||
private static final int retryTimes = 100;
|
||||
private static final int httpCodeLimitReached = 429;
|
||||
private static int athleteId = 0;
|
||||
private static int athleteId = -1;
|
||||
private static JSONParser parser = new JSONParser();
|
||||
private static String testRequest;
|
||||
private static File errorFile;
|
||||
@@ -191,7 +191,8 @@ public class Main
|
||||
int pageIndex = 1;
|
||||
while (true)
|
||||
{
|
||||
String requestExtension = "athlete/activities?per_page=500&page=" + pageIndex;
|
||||
//TODO: this 'per_page' value could perhaps be the root of all evil
|
||||
String requestExtension = "athlete/activities?per_page=100&page=" + pageIndex;
|
||||
String json = makeGetRequestWithRetry(requestExtension, token);
|
||||
if (json==null || json.isEmpty() || json.isBlank() || json.equals("") || json.equals("[]")) // don't know where the last page is...
|
||||
{
|
||||
@@ -279,6 +280,7 @@ public class Main
|
||||
//tried enough times, so stop now
|
||||
if(count >= retryTimes)
|
||||
{
|
||||
writeError("Athlete: "+athleteId+" Retry limit reached. Last error code: "+e.getResponseCode());
|
||||
return null;
|
||||
}
|
||||
//request limit is reached, try again later
|
||||
@@ -341,6 +343,11 @@ public class Main
|
||||
writeError("Athlete " + athleteId + ": Error parsing general information.");
|
||||
return null;
|
||||
}
|
||||
catch (NullPointerException e)
|
||||
{
|
||||
writeError("Athlete " + athleteId + ": No general information found.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -415,7 +422,7 @@ public class Main
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
writeError("Error while handling GET request: " + e.toString());
|
||||
writeError("Athlete: "+athleteId+" Error while handling GET request: " + e.toString());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
@@ -437,7 +444,7 @@ public class Main
|
||||
//excluded error messages appearing on missing streams and reached rate limit
|
||||
if(responseCode != HttpURLConnection.HTTP_NOT_FOUND && responseCode!= httpCodeLimitReached)
|
||||
{
|
||||
writeError("Wrong response code: " + responseCode);
|
||||
writeError("Athlete: "+athleteId+" Wrong response code: " + responseCode);
|
||||
}
|
||||
throw new ResponseCodeWrongException(responseCode);
|
||||
}
|
||||
@@ -503,7 +510,7 @@ public class Main
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
writeError("Error while handling POST request: " + e.toString());
|
||||
writeError("Athlete: "+athleteId+"Error while handling POST request: " + e.toString());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
@@ -579,11 +586,12 @@ public class Main
|
||||
int zipcount =1;
|
||||
for (Triplet oneUser : refreshTokens)
|
||||
{
|
||||
athleteId++;
|
||||
// a is access_token and b is new refresh_token
|
||||
Tuple withAccessToken = getAccessToken(oneUser);
|
||||
if (withAccessToken == null)
|
||||
{
|
||||
writeError("Coulnd't get new access token for client "+athleteId);
|
||||
writeError("Couldn't get new access token for client "+athleteId);
|
||||
continue;
|
||||
}
|
||||
newRefreshTokens.add(new Triplet(oneUser.getA(), oneUser.getB(), withAccessToken.getB()));
|
||||
@@ -607,7 +615,6 @@ public class Main
|
||||
writeError("Files coulnd't be zipped");
|
||||
}
|
||||
}
|
||||
athleteId++;
|
||||
}
|
||||
//zip the rest
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user