add error handling/reporting for client module

Change-Id: I38875e561aa85093030ad6f937891723bd401de2
diff --git a/src/client-module.cpp b/src/client-module.cpp
index 8fdb7b2..46405bb 100644
--- a/src/client-module.cpp
+++ b/src/client-module.cpp
@@ -35,6 +35,8 @@
 #include "protocol-detail/new.hpp"
 #include "protocol-detail/probe.hpp"
 #include "protocol-detail/revoke.hpp"
+#include "protocol-detail/error.hpp"
+#include "ndncert-common.hpp"
 
 namespace ndn {
 namespace ndncert {
@@ -123,6 +125,9 @@
     return;
   }
 
+  // error handling
+  processIfError(reply);
+
   auto contentTLV = reply.getContent();
   contentTLV.parse();
 
@@ -217,6 +222,10 @@
     _LOG_ERROR("Cannot verify data signature from " << m_ca.m_caPrefix.toUri());
     return std::list<std::string>();
   }
+
+  // error handling
+  processIfError(reply);
+
   auto contentTLV = reply.getContent();
   contentTLV.parse();
 
@@ -300,6 +309,10 @@
     _LOG_ERROR("Cannot verify data signature from " << m_ca.m_caPrefix.toUri());
     return;
   }
+
+  // error handling
+  processIfError(reply);
+
   auto result = decodeBlockWithAesGcm128(reply.getContent(), m_aesKey, (const uint8_t*)"test", strlen("test"));
 
   Block contentTLV = makeBinaryBlock(tlv_encrypted_payload, result.data(), result.size());
@@ -373,5 +386,22 @@
   m_status = Status::ENDED;
 }
 
+void
+ClientModule::processIfError(const Data& data)
+{
+  auto contentTLV = data.getContent();
+  if (ErrorTLV::isErrorContent(contentTLV)) {
+  try {
+    auto error = ErrorTLV::decodefromDataContent(contentTLV);
+    _LOG_ERROR("Error data returned for " << data.getName() << ": " << std::endl <<
+               "Code: " << errorCodeToString(std::get<0>(error)) << std::endl <<
+               "Info: " << std::get<1>(error) << std::endl);
+    } catch (const std::exception& e) {
+      _LOG_ERROR("Cannot parse error data content for " << data.getName());
+      return;
+    }
+  }
+}
+
 }  // namespace ndncert
 }  // namespace ndn