]> WPIA git - gigi.git/commitdiff
Increase verbosity of reping error message.
authorFelix Dörre <felix@dogcraft.de>
Sat, 31 Jan 2015 23:44:36 +0000 (00:44 +0100)
committerFelix Dörre <felix@dogcraft.de>
Sat, 31 Jan 2015 23:44:36 +0000 (00:44 +0100)
src/org/cacert/gigi/GigiApiException.java
src/org/cacert/gigi/dbObjects/DomainPingConfiguration.java

index e766d9ea9e6e56b50fa87ec69c61924da05f4c7a..b858e7d9a35d662c5ecefc10375d9a798d33349b 100644 (file)
@@ -1,16 +1,21 @@
 package org.cacert.gigi;
 
 import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.sql.SQLException;
+import java.util.HashMap;
 import java.util.LinkedList;
+import java.util.Locale;
 
 import org.cacert.gigi.localisation.Language;
+import org.cacert.gigi.output.template.Outputable;
+import org.cacert.gigi.output.template.TranslateCommand;
 
 public class GigiApiException extends Exception {
 
     private SQLException e;
 
-    private LinkedList<String> messages = new LinkedList<>();
+    private LinkedList<Outputable> messages = new LinkedList<>();
 
     public GigiApiException(SQLException e) {
         super(e);
@@ -19,13 +24,17 @@ public class GigiApiException extends Exception {
 
     public GigiApiException(String message) {
         super(message);
-        messages.add(message);
+        messages.add(new TranslateCommand(message));
     }
 
     public GigiApiException() {
 
     }
 
+    public GigiApiException(Outputable out) {
+        messages.add(out);
+    }
+
     public void mergeInto(GigiApiException e2) {
         messages.addAll(e2.messages);
         if (e == null) {
@@ -45,9 +54,12 @@ public class GigiApiException extends Exception {
             out.println(language.getTranslation("An internal error ouccured."));
             out.println("</div>");
         }
-        for (String message : messages) {
+        HashMap<String, Object> map = new HashMap<>();
+        for (Outputable message : messages) {
+            map.clear();
+
             out.print("<div>");
-            out.print(language.getTranslation(message));
+            message.output(out, language, map);
             out.println("</div>");
         }
         out.println("</div>");
@@ -61,11 +73,17 @@ public class GigiApiException extends Exception {
     @Override
     public String getMessage() {
         if (messages.size() != 0) {
-            StringBuffer res = new StringBuffer();
-            for (String string : messages) {
-                res.append(string + "\n");
+            StringWriter sw = new StringWriter();
+            PrintWriter pw = new PrintWriter(sw);
+
+            HashMap<String, Object> map = new HashMap<>();
+            for (Outputable message : messages) {
+                map.clear();
+                message.output(pw, Language.getInstance(Locale.ENGLISH), map);
             }
-            return res.toString();
+            pw.flush();
+
+            return sw.toString();
         }
         return "";
     }
index cf1292b8a072ffa744f86e7a203c7fdc00d81514..e27b696d829cbc432a782546c19c5918135ad116 100644 (file)
@@ -1,12 +1,17 @@
 package org.cacert.gigi.dbObjects;
 
+import java.util.Arrays;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.cacert.gigi.Gigi;
 import org.cacert.gigi.GigiApiException;
 import org.cacert.gigi.database.DatabaseConnection;
 import org.cacert.gigi.database.GigiPreparedStatement;
 import org.cacert.gigi.database.GigiResultSet;
+import org.cacert.gigi.output.template.Scope;
+import org.cacert.gigi.output.template.SprintfCommand;
 
 public class DomainPingConfiguration implements IdCachable {
 
@@ -89,7 +94,8 @@ public class DomainPingConfiguration implements IdCachable {
             Gigi.notifyPinger(this);
             return;
         }
-        throw new GigiApiException("Reping is only allowed after 5 minutes");
+        Map<String, Object> data = new HashMap<String, Object>();
+        data.put("data", new Date(lastExecution.getTime() + 5 * 60 * 1000));
+        throw new GigiApiException(new Scope(new SprintfCommand("Reping is only allowed after 5 minutes, yours end at %s.", Arrays.asList("$data")), data));
     }
-
 }