added exception hadling to JSON readings sending
added exception hadling to JSON readings sending
@@ -244,6 +244,8 @@ uint32_t OMF::sendToServer(const vector<Reading *>& readings,
// Build an HTTPS POST with 'readingData headers
// and 'allReadings' JSON payload
// Then get HTTPS POST ret code and return 0 to client on error
+ try
+ {
int res = m_sender.sendRequest("POST", m_path, readingData, jsonData.str());
if (res != 200 && res != 204)
{
@@ -257,6 +259,13 @@ uint32_t OMF::sendToServer(const vector<Reading *>& readings,
// Return number of sen t readings to the caller
return readings.size();
}
+ catch (const std::exception& e)
+ {
+ Logger::getLogger()->error("Sending JSON data error: %s", e.what());
+ m_lastError = true;
+ return 0;
+ }
+}
/**
* Send all the readings to the PI Server
