diff --git a/http_examples.cpp b/http_examples.cpp index 87234e3..8ad98a5 100644 --- a/http_examples.cpp +++ b/http_examples.cpp @@ -226,13 +226,19 @@ int main() { // Client examples HttpClient client("localhost:8080"); - // Synchronous request examples - auto r1 = client.request("GET", "/match/123"); - cout << r1->content.rdbuf() << endl; // Alternatively, use the convenience function r1->content.string() - string json_string = "{\"firstName\": \"John\",\"lastName\": \"Smith\",\"age\": 25}"; - auto r2 = client.request("POST", "/string", json_string); - cout << r2->content.rdbuf() << endl; + + // Synchronous request examples + try { + auto r1 = client.request("GET", "/match/123"); + cout << r1->content.rdbuf() << endl; // Alternatively, use the convenience function r1->content.string() + + auto r2 = client.request("POST", "/string", json_string); + cout << r2->content.rdbuf() << endl; + } + catch(const SimpleWeb::system_error &e) { + cerr << "Client request error: " << e.what() << endl; + } // Asynchronous request example client.request("POST", "/json", json_string, [](shared_ptr response, const SimpleWeb::error_code &ec) { diff --git a/https_examples.cpp b/https_examples.cpp index 85d4184..6cf08d0 100644 --- a/https_examples.cpp +++ b/https_examples.cpp @@ -225,13 +225,19 @@ int main() { // Second create() parameter set to false: no certificate verification HttpsClient client("localhost:8080", false); - // Synchronous request examples - auto r1 = client.request("GET", "/match/123"); - cout << r1->content.rdbuf() << endl; // Alternatively, use the convenience function r1->content.string() - string json_string = "{\"firstName\": \"John\",\"lastName\": \"Smith\",\"age\": 25}"; - auto r2 = client.request("POST", "/string", json_string); - cout << r2->content.rdbuf() << endl; + + // Synchronous request examples + try { + auto r1 = client.request("GET", "/match/123"); + cout << r1->content.rdbuf() << endl; // Alternatively, use the convenience function r1->content.string() + + auto r2 = client.request("POST", "/string", json_string); + cout << r2->content.rdbuf() << endl; + } + catch(const SimpleWeb::system_error &e) { + cerr << "Client request error: " << e.what() << endl; + } // Asynchronous request example client.request("POST", "/json", json_string, [](shared_ptr response, const SimpleWeb::error_code &ec) {