Error handling
FossilOrigin-Name: 7d76b3601243328c356a06828be47e6003fb5d81bdaba8051065506686b4eee7
This commit is contained in:
parent
a9692464ad
commit
47bf9de602
3 changed files with 10 additions and 13 deletions
|
@ -34,16 +34,17 @@ int mastodont_account(mastodont_t* data,
|
|||
id);
|
||||
storage->needs_cleanup = 0;
|
||||
|
||||
res = mastodont_fetch_curl(data, url, &results);
|
||||
if (mastodont_fetch_curl(data, url, &results) != CURLE_OK)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* TODO cleanup this */
|
||||
root = cJSON_ParseWithLength(results.response, results.size);
|
||||
|
||||
if (root == NULL)
|
||||
{
|
||||
const char* jerror = cJSON_GetErrorPtr();
|
||||
if (jerror)
|
||||
fprintf(stderr, "cJSON_Parse: %s\n", jerror);
|
||||
res = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
storage->root = root;
|
||||
|
|
|
@ -60,10 +60,6 @@ int mastodont_fetch_curl(mastodont_t* mstdnt,
|
|||
curl_easy_setopt(mstdnt->curl, CURLOPT_WRITEDATA, results);
|
||||
|
||||
res = curl_easy_perform(mstdnt->curl);
|
||||
if (res != CURLE_OK)
|
||||
{
|
||||
printf("curl_easy_perform: %s\n", curl_easy_strerror(res));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -44,14 +44,13 @@ int mastodont_timeline_public(mastodont_t* data,
|
|||
}
|
||||
storage->needs_cleanup = 0;
|
||||
|
||||
res = mastodont_fetch_curl(data, "api/v1/timelines/public", &results);
|
||||
if (mastodont_fetch_curl(data, "api/v1/timelines/public", &results) != CURLE_OK)
|
||||
return 1;
|
||||
|
||||
root = cJSON_ParseWithLength(results.response, results.size);
|
||||
if (root == NULL)
|
||||
{
|
||||
const char* jerror = cJSON_GetErrorPtr();
|
||||
if (jerror)
|
||||
fprintf(stderr, "cJSON_Parse: %s\n", jerror);
|
||||
res = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
storage->root = root;
|
||||
|
@ -60,6 +59,7 @@ int mastodont_timeline_public(mastodont_t* data,
|
|||
if (!cJSON_IsArray(root))
|
||||
{
|
||||
/* Likely an error */
|
||||
res = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ int mastodont_timeline_public(mastodont_t* data,
|
|||
* sizeof(struct mstdnt_status));
|
||||
if (*statuses == NULL)
|
||||
{
|
||||
perror("malloc");
|
||||
res = 1;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue