This repository was archived by the owner on Jan 23, 2026. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1919
2020class BarcodeFactory {
2121public:
22- static std::unique_ptr<IBarcodeGenerator> create (const std::string type);
22+ static std::unique_ptr<IBarcodeGenerator> create (const std::string type);
2323};
Original file line number Diff line number Diff line change 66#include < ZXing/CharacterSet.h>
77#include < ZXing/MultiFormatWriter.h>
88#include < memory>
9+ #include < stdexcept>
910#include < string>
1011#include < utility>
1112
@@ -18,13 +19,21 @@ int main() {
1819 auto margin = req.url_params .get (" margin" );
1920 auto size = req.url_params .get (" size" );
2021 std::unique_ptr<IBarcodeGenerator> generator = BarcodeFactory::create (type);
21- std::string matrix =
22- generator->generate (text, std::stoi (margin), std::stoi (size));
2322
23+ std::string matrix;
2424 crow::response resp;
25- resp.code = 200 ;
26- resp.add_header (" Content-Type" , " image/svg+xml" );
27- resp.body = std::move (matrix);
25+ try {
26+ matrix = generator->generate (text, std::stoi (margin), std::stoi (size));
27+
28+ resp.code = 200 ;
29+ resp.add_header (" Content-Type" , " image/svg+xml" );
30+ resp.body = std::move (matrix);
31+ } catch (const std::invalid_argument &ex) {
32+ std::cerr << ex.what () << std::endl;
33+ resp.code = 400 ;
34+ resp.add_header (" Content-Type" , " text/html" );
35+ resp.body = std::move (matrix);
36+ }
2837
2938 return resp;
3039 });
You can’t perform that action at this time.
0 commit comments