From 7dfb8c1257a2aba029bc85cd6330ea12c3e25637 Mon Sep 17 00:00:00 2001 From: "me@ow.nekobit.net" Date: Thu, 31 Mar 2022 11:00:33 +0000 Subject: [PATCH] Notification error handling, prettier timeline errors FossilOrigin-Name: 88be2a384e2acdd83ab6dbbf97ef75a80d7a978f43500694c339d44b51ba0e8d --- src/notifications.c | 7 ++++++- src/timeline.c | 7 +++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/notifications.c b/src/notifications.c index 847cf64..8c6ee5c 100644 --- a/src/notifications.c +++ b/src/notifications.c @@ -23,6 +23,7 @@ #include "string_helpers.h" #include "easprintf.h" #include "status.h" +#include "error.h" // Pages #include "../static/notifications_page.chtml" @@ -134,9 +135,13 @@ void content_notifications(struct session* ssn, mastodont_t* api, char** data) }; if (mastodont_get_notifications(api, &args, &storage, ¬ifs, ¬ifs_len) == 0) + { notif_html = construct_notifications(notifs, notifs_len, NULL); + mstdnt_cleanup_notifications(notifs, notifs_len); + } + else + notif_html = construct_error("Couldn't load notifications", NULL); - mstdnt_cleanup_notifications(notifs, notifs_len); } easprintf(&page, data_notifications_page_html, diff --git a/src/timeline.c b/src/timeline.c index 6c8c132..b4c1e27 100644 --- a/src/timeline.c +++ b/src/timeline.c @@ -26,13 +26,13 @@ #include "reply.h" #include "navigation.h" #include "query.h" +#include "error.h" #include "string_helpers.h" #include "../static/navigation.chtml" void tl_public(struct session* ssn, mastodont_t* api, int local) { - int cleanup = 0; size_t status_count, statuses_html_count; struct mstdnt_status* statuses = NULL; struct mstdnt_storage storage = { 0 }; @@ -56,14 +56,13 @@ void tl_public(struct session* ssn, mastodont_t* api, int local) if (mastodont_timeline_public(api, &args, &storage, &statuses, &status_count)) { - status_format = "An error occured loading the timeline"; + status_format = construct_error("An error occured loading the timeline", NULL); } else { // Construct statuses into HTML status_format = construct_statuses(statuses, status_count, &statuses_html_count); if (!status_format) status_format = "Error in malloc!"; - cleanup = 1; } // Create post box @@ -95,7 +94,7 @@ void tl_public(struct session* ssn, mastodont_t* api, int local) // Cleanup mastodont_storage_cleanup(&storage); mstdnt_cleanup_statuses(statuses, status_count); - if (cleanup) free(status_format); + if (status_format) free(status_format); if (post_box) free(post_box); if (navigation_box) free(navigation_box); if (output) free(output);