add error handling for addRequest

Change-Id: I46dfef76735f14abc1dc8d0a1d618a1963d4f8a0
diff --git a/src/ca-module.cpp b/src/ca-module.cpp
index f674482..802049a 100644
--- a/src/ca-module.cpp
+++ b/src/ca-module.cpp
@@ -328,7 +328,13 @@
   std::string requestId = std::to_string(random::generateWord64());
   CaState requestState(m_config.m_caItem.m_caPrefix, requestId, requestType, Status::BEFORE_CHALLENGE, *clientCert,
                        makeBinaryBlock(tlv::ContentType_Key, aesKey, sizeof(aesKey)));
-  m_storage->addRequest(requestState);
+  try {
+    m_storage->addRequest(requestState);
+  }
+  catch (const std::runtime_error& e) {
+    requestId = std::to_string(random::generateWord64());
+    m_storage->addRequest(requestState);
+  }
   Data result;
   result.setName(request.getName());
   result.setFreshnessPeriod(DEFAULT_DATA_FRESHNESS_PERIOD);
diff --git a/src/ca-storage-detail/ca-memory.hpp b/src/ca-storage-detail/ca-memory.hpp
index eeb3397..754090e 100644
--- a/src/ca-storage-detail/ca-memory.hpp
+++ b/src/ca-storage-detail/ca-memory.hpp
@@ -33,10 +33,15 @@
   const static std::string STORAGE_TYPE;
 
 public:
-  // certificate request related
+  /**
+   * @throw if request cannot be fetched from underlying data storage
+   */
   CaState
   getRequest(const std::string& requestId) override;
 
+  /**
+   * @throw if there is an existing request with the same request ID
+   */
   void
   addRequest(const CaState& request) override;
 
diff --git a/src/ca-storage-detail/ca-sqlite.hpp b/src/ca-storage-detail/ca-sqlite.hpp
index e97b15c..b3988c0 100644
--- a/src/ca-storage-detail/ca-sqlite.hpp
+++ b/src/ca-storage-detail/ca-sqlite.hpp
@@ -40,10 +40,15 @@
   ~CaSqlite();
 
 public:
-  // request related
+  /**
+   * @throw if request cannot be fetched from underlying data storage
+   */
   CaState
   getRequest(const std::string& requestId) override;
 
+  /**
+   * @throw if there is an existing request with the same request ID
+   */
   void
   addRequest(const CaState& request) override;
 
diff --git a/src/ca-storage.hpp b/src/ca-storage.hpp
index c2ca1c5..7fbc1ec 100644
--- a/src/ca-storage.hpp
+++ b/src/ca-storage.hpp
@@ -29,9 +29,15 @@
 class CaStorage : noncopyable
 {
 public: // request related
+  /**
+   * @throw if request cannot be fetched from underlying data storage
+   */
   virtual CaState
   getRequest(const std::string& requestId) = 0;
 
+  /**
+   * @throw if there is an existing request with the same request ID
+   */
   virtual void
   addRequest(const CaState& request) = 0;