forked from cpp/cWikiBot
Retry up to 5 times, when an error occurs.
This commit is contained in:
parent
8bd06434e3
commit
0189bcc0d0
1 changed files with 6 additions and 2 deletions
|
@ -12,14 +12,18 @@ json_object* query_lichess(char* username)
|
||||||
*/
|
*/
|
||||||
char* api_base = "https://lichess.org/api/user/";
|
char* api_base = "https://lichess.org/api/user/";
|
||||||
char user_url[128];
|
char user_url[128];
|
||||||
|
int retries = 5;
|
||||||
strcpy(user_url,api_base);
|
strcpy(user_url,api_base);
|
||||||
strcat(user_url,username);
|
strcat(user_url,username);
|
||||||
printf("querying %s\n",user_url);
|
printf("querying %s\n",user_url);
|
||||||
char* http_response = request(user_url);
|
char* http_response = request(user_url);
|
||||||
if(http_response == NULL)
|
while(http_response == NULL)
|
||||||
{
|
{
|
||||||
printf("didn't receive HTTP response, we might be rate-limited. Waiting 60s");
|
printf("didn't receive HTTP response, we might be rate-limited. Waiting 60s");
|
||||||
sleep(60);
|
sleep(60);
|
||||||
|
http_response = request(user_url);
|
||||||
|
retries--;
|
||||||
|
if(retries == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
json_object *lichessUser = json_tokener_parse(http_response);
|
json_object *lichessUser = json_tokener_parse(http_response);
|
||||||
|
|
Loading…
Reference in a new issue