- // sending request
- restclient::RestClient client( ts_control_ep );
- restclient::response_t resp = client.do_post( "", msg ); // we already have the full path in ts_control_ep
-
- if( resp.status_code == 200 ) {
- // ============== DO SOMETHING USEFUL HERE ===============
- // Currently, we only print out the HandOff reply
- rapidjson::Document document;
- document.Parse( resp.body.c_str() );
- rapidjson::StringBuffer s;
- rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(s);
- document.Accept( writer );
- cout << "[INFO] HandOff reply is " << s.GetString() << endl;
+ try {
+ // sending request
+ restclient::RestClient client( ts_control_ep );
+ restclient::response_t resp = client.do_post( "", msg ); // we already have the full path in ts_control_ep
+
+ if( resp.status_code == 200 ) {
+ // ============== DO SOMETHING USEFUL HERE ===============
+ // Currently, we only print out the HandOff reply
+ rapidjson::Document document;
+ document.Parse( resp.body.c_str() );
+ rapidjson::StringBuffer s;
+ rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(s);
+ document.Accept( writer );
+ cout << "[INFO] HandOff reply is " << s.GetString() << endl;
+
+ } else {
+ cout << "[ERROR] Unexpected HTTP code " << resp.status_code << " from " << \
+ client.getBaseUrl() << \
+ "\n[ERROR] HTTP payload is " << resp.body.c_str() << endl;
+ }
+
+ } catch( const restclient::RestClientException &e ) {
+ cout << "[ERROR] " << e.what() << endl;