Fix remote save, better GUI if bad import url
authorNiki Roo <niki@nikiroo.be>
Sat, 2 Dec 2017 15:33:14 +0000 (16:33 +0100)
committerNiki Roo <niki@nikiroo.be>
Sat, 2 Dec 2017 15:33:14 +0000 (16:33 +0100)
src/be/nikiroo/fanfix/library/BasicLibrary.java
src/be/nikiroo/fanfix/library/RemoteLibraryServer.java
src/be/nikiroo/fanfix/reader/GuiReaderFrame.java

index 430fb2026a256510bb7705eea22ce799005ab48e..42c6c9d843063dc64956dc90e285ac476e068b1d 100644 (file)
@@ -4,6 +4,7 @@ import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
+import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -368,13 +369,15 @@ abstract public class BasicLibrary {
         * 
         * @return the imported {@link Story}
         * 
+        * @throws UnknownHostException
+        *             if the host is not supported
         * @throws IOException
         *             in case of I/O error
         */
        public Story imprt(URL url, Progress pg) throws IOException {
                BasicSupport support = BasicSupport.getSupport(url);
                if (support == null) {
-                       throw new IOException("URL not supported: " + url.toString());
+                       throw new UnknownHostException("" + url);
                }
 
                return save(support.process(url, pg), null);
index 84d763fce51f5c4ad97cfd1fda07d41dee71845c..6a62b6f09e5373e0afcd0151019cebc3dc21084c 100644 (file)
@@ -130,7 +130,7 @@ public class RemoteLibraryServer extends ServerObject {
                        }
 
                        Story story = rebuildStory(list);
-                       Instance.getLibrary().save(story, "" + args[1], null);
+                       Instance.getLibrary().save(story, "" + args[0], null);
                } else if ("DELETE_STORY".equals(command)) {
                        Instance.getLibrary().delete("" + args[0]);
                } else if ("GET_COVER".equals(command)) {
index 4e2630ec9e3258fc6b9be5d2373f3027582e9eed..9174380aa507526e4cdc1fba62cf771b967f4353 100644 (file)
@@ -13,6 +13,7 @@ import java.awt.event.WindowEvent;
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
+import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -987,8 +988,13 @@ class GuiReaderFrame extends JFrame {
 
                                pgOnSuccess.setProgress(0);
                                if (!ok) {
-                                       error("Cannot import URL", "Failed to import " + url
-                                                       + ": \n" + e.getMessage(), e);
+                                       if (e instanceof UnknownHostException) {
+                                               error("Failed to import " + url, "Cannot import URL",
+                                                               null);
+                                       } else {
+                                               error("Failed to import " + url + ": \n"
+                                                               + e.getMessage(), "Cannot import URL", e);
+                                       }
                                } else {
                                        if (onSuccess != null) {
                                                onSuccess.run(story);