From 600edb6b68173ae931aaa88d74573964d5306224 Mon Sep 17 00:00:00 2001 From: Physick <96335032+DegustatorPonos@users.noreply.github.com> Date: Sun, 10 May 2026 20:58:10 +0500 Subject: Better error handling --- .gitignore | 2 +- news | Bin 702280 -> 702152 bytes src/RSS.cpp | 24 ++++++++++++++++-------- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 6db993a..4327969 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -app +news diff --git a/news b/news index c6c2332..a0eabba 100755 Binary files a/news and b/news differ diff --git a/src/RSS.cpp b/src/RSS.cpp index 93c391d..20c809f 100644 --- a/src/RSS.cpp +++ b/src/RSS.cpp @@ -48,18 +48,24 @@ std::string RSS::request() { curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA, &data); curl_easy_setopt(curl.get(), CURLOPT_FOLLOWLOCATION, 1L); + curl_easy_setopt(curl.get(), CURLOPT_CONNECTTIMEOUT, 2L); - auto res = curl_easy_perform(curl.get()); - if (res != CURLE_OK) { - throw std::runtime_error(std::string("CURL request failed: ") + curl_easy_strerror(res)); + try { + auto res = curl_easy_perform(curl.get()); + if (res != CURLE_OK) { + // throw std::runtime_error(std::string("CURL request failed: ") + curl_easy_strerror(res)); + return ""; + } + + return data; + } catch (const std::exception& e) { + return ""; } - - curl_easy_cleanup(curl.get()); - return data; } void RSS::parse(std::string contents) { // std::cout << "starting tokenization..." << std::endl; + if (contents.length() == 0) return; try { auto leaf = XML_leaf(contents).GetChild("channel"); if (leaf.Raw == "<>") @@ -91,6 +97,8 @@ void RSS::print_latest(int minutesSpan) { std::tm* gmt_time = std::gmtime(&now); gmt_time->tm_min -= minutesSpan; auto ticks = std::mktime(gmt_time); + // std::cout << "starting time: " << std::put_time(gmt_time, "%Y-%m-%d %H:%M:%S") << std::endl; + for (auto entry : Entries) { if (entry.pubDate.tm_year == 0 || std::mktime(&entry.pubDate) < ticks) break; @@ -110,10 +118,10 @@ RSS_Entry::RSS_Entry(XML_leaf node) { void RSS_Entry::print() { std::cout - << Title << '\n' + << "\033[1m" << Title << "\033[0m" << '\n' << std::put_time(&pubDate, "%Y-%m-%d %H:%M:%S") << '\n' << Contents << '\n' - << URL<< '\n' + << URL << '\n' << "==============================\n"; } -- cgit v1.3