From 31ab522fb80473676ff31f3434f4651a1a4ee1a3 Mon Sep 17 00:00:00 2001 From: Aotrix Date: Thu, 27 Mar 2025 02:48:28 +0100 Subject: added exception handler for transactions --- src/main.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 27397f0..bf1d53d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,12 +9,19 @@ int main() { "postgresql://aotrix@localhost:5432/hearthstonegameinfo"}; pqxx::work tx{cx}; - const unsigned int card_id = 217; - std::string card = - hs_handler.get_cards(std::format("/{}?locale=fr_FR", card_id)); - std::cout << card << std::endl; - add_cards_to_database(card, tx); - - tx.commit(); + try { + std::string cards = hs_handler.get_cards( + "/108499?locale=fr_FR&gameMode=constructed&pageSize=2"); + std::cout << cards << std::endl; + add_cards_to_database(cards, tx); + tx.commit(); + } catch (pqxx::sql_error const &e) { + std::cerr << "SQL error: " << e.what() << std::endl; + std::cerr << "Query was: " << e.query() << std::endl; + return 2; + } catch (std::exception const &e) { + std::cerr << "Error: " << e.what() << std::endl; + return 1; + } return 0; } -- cgit v1.2.3