From e2c9a08bb404f4221e58c03f2a1dd305de21fa2c Mon Sep 17 00:00:00 2001 From: Chebo7 <192.cpp@gmail.com> Date: Wed, 3 Dec 2025 22:33:53 +0300 Subject: [PATCH 1/2] During development, I returned the port to 8080 so as not to constantly run the server as superuser. --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index a37b2c1..a9daaa6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,5 +29,5 @@ int main() { return resp; }); - app.port(80).multithreaded().run(); + app.port(8080).multithreaded().run(); } From 2a71521235e87b15918adb0cdbd28a37d4dcd739 Mon Sep 17 00:00:00 2001 From: Chebo7 <192.cpp@gmail.com> Date: Thu, 4 Dec 2025 16:38:33 +0300 Subject: [PATCH 2/2] Added minimal error and exception handling --- include/Barcode/BarcodeFactory.h | 2 +- src/main.cpp | 19 ++++++++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/include/Barcode/BarcodeFactory.h b/include/Barcode/BarcodeFactory.h index 75becd9..4d94915 100644 --- a/include/Barcode/BarcodeFactory.h +++ b/include/Barcode/BarcodeFactory.h @@ -19,5 +19,5 @@ class BarcodeFactory { public: - static std::unique_ptr create(const std::string type); + static std::unique_ptr create(const std::string type); }; diff --git a/src/main.cpp b/src/main.cpp index a9daaa6..842321c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -18,13 +19,21 @@ int main() { auto margin = req.url_params.get("margin"); auto size = req.url_params.get("size"); std::unique_ptr generator = BarcodeFactory::create(type); - std::string matrix = - generator->generate(text, std::stoi(margin), std::stoi(size)); + std::string matrix; crow::response resp; - resp.code = 200; - resp.add_header("Content-Type", "image/svg+xml"); - resp.body = std::move(matrix); + try { + matrix = generator->generate(text, std::stoi(margin), std::stoi(size)); + + resp.code = 200; + resp.add_header("Content-Type", "image/svg+xml"); + resp.body = std::move(matrix); + } catch (const std::invalid_argument &ex) { + std::cerr << ex.what() << std::endl; + resp.code = 400; + resp.add_header("Content-Type", "text/html"); + resp.body = std::move(matrix); + } return resp; });