make key generation throw exceptions in case of errors
[jSite2.git] / src / net / pterodactylus / jsite / core / NodeManager.java
index f772dc2..b9404c7 100644 (file)
@@ -429,17 +429,20 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
         *         public key at index <code>1</code>
         * @throws IOException
         *             if an I/O error occurs communicating with the node
+        * @throws NoNodeException
+        *             if no node is configured
         */
-       public String[] generateKeyPair() throws IOException {
-               if (!nodes.isEmpty()) {
-                       Node node = nodes.get(0);
-                       HighLevelClient highLevelClient = nodeClients.get(node);
-                       try {
-                               KeyGenerationResult keyGenerationResult = highLevelClient.generateKey().getResult();
-                               return new String[] { keyGenerationResult.getInsertURI(), keyGenerationResult.getRequestURI() };
-                       } catch (InterruptedException e) {
-                               /* ignore. */
-                       }
+       public String[] generateKeyPair() throws IOException, NoNodeException {
+               if (nodes.isEmpty()) {
+                       throw new NoNodeException("no node configured");
+               }
+               Node node = nodes.get(0);
+               HighLevelClient highLevelClient = nodeClients.get(node);
+               try {
+                       KeyGenerationResult keyGenerationResult = highLevelClient.generateKey().getResult();
+                       return new String[] { keyGenerationResult.getInsertURI(), keyGenerationResult.getRequestURI() };
+               } catch (InterruptedException e) {
+                       /* ignore. */
                }
                return null;
        }