Handle list errors

FossilOrigin-Name: d3aa61e2ff4bbc189e0f7953a7fbdf3a8ba19d95800487ae7eede6082606aacb
This commit is contained in:
me@ow.nekobit.net 2022-04-11 21:04:48 +00:00
parent 22483e4e4a
commit 78766ee1e1
2 changed files with 6 additions and 10 deletions

View file

@ -63,11 +63,10 @@ char* construct_lists_view(char* lists_string, int* size)
void content_lists(struct session* ssn, mastodont_t* api, char** data)
{
int cleanup = 0;
struct mstdnt_list* lists;
size_t size_list;
struct mstdnt_storage storage = { 0 };
char* lists_format;
char* lists_format = NULL;
char* lists_page = NULL;
if (mastodont_get_lists(api, &lists, &storage, &size_list))
@ -77,8 +76,7 @@ void content_lists(struct session* ssn, mastodont_t* api, char** data)
else {
lists_format = construct_lists(lists, size_list, NULL);
if (!lists_format)
lists_format = "Error in malloc!";
cleanup = 1;
lists_format = construct_error("No lists", E_ERROR, 1, NULL);
lists_page = construct_lists_view(lists_format, NULL);
}
@ -94,6 +92,6 @@ void content_lists(struct session* ssn, mastodont_t* api, char** data)
// Cleanup
mastodont_storage_cleanup(&storage);
if (cleanup) free(lists_format);
if (lists_format) free(lists_format);
if (lists_page) free(lists_page);
}

View file

@ -102,7 +102,6 @@ void tl_public(struct session* ssn, mastodont_t* api, int local)
void tl_list(struct session* ssn, mastodont_t* api, char* list_id)
{
int cleanup = 0;
size_t status_count, statuses_html_count;
struct mstdnt_status* statuses;
struct mstdnt_storage storage = { 0 };
@ -120,14 +119,13 @@ void tl_list(struct session* ssn, mastodont_t* api, char* list_id)
if (mastodont_timeline_list(api, list_id, &args, &storage, &statuses, &status_count))
{
status_format = "An error occured loading the timeline";
status_format = construct_error(storage.error, E_ERROR, 1, NULL);
}
else {
// Construct statuses into HTML
status_format = construct_statuses(api, statuses, status_count, &statuses_html_count);
if (!status_format)
status_format = "Error in malloc!";
cleanup = 1;
status_format = construct_error("No statuses", E_ERROR, 1, NULL);
}
// Create post box
@ -149,7 +147,7 @@ void tl_list(struct session* ssn, mastodont_t* api, char* list_id)
// Cleanup
mastodont_storage_cleanup(&storage);
mstdnt_cleanup_statuses(statuses, status_count);
if (cleanup) free(status_format);
free(status_format);
if (post_box) free(post_box);
if (output) free(output);
}