X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=src%2Forg%2Fcacert%2Fgigi%2FGigiApiException.java;h=e766d9ea9e6e56b50fa87ec69c61924da05f4c7a;hb=3395fce1b4cf2ad4a01536f6aeabd59951ccee08;hp=7b91d125fb1d200a4e1a822ab7dac70bbf3a693a;hpb=562f4e5fabe180a8dfc4894241a89cae0d1655ee;p=gigi.git diff --git a/src/org/cacert/gigi/GigiApiException.java b/src/org/cacert/gigi/GigiApiException.java index 7b91d125..e766d9ea 100644 --- a/src/org/cacert/gigi/GigiApiException.java +++ b/src/org/cacert/gigi/GigiApiException.java @@ -4,54 +4,70 @@ import java.io.PrintWriter; import java.sql.SQLException; import java.util.LinkedList; +import org.cacert.gigi.localisation.Language; + public class GigiApiException extends Exception { - SQLException e; - LinkedList messages = new LinkedList<>(); - - public GigiApiException(SQLException e) { - super(e); - this.e = e; - } - - public GigiApiException(String message) { - super(message); - messages.add(message); - } - - public GigiApiException() { - - } - - public void mergeInto(GigiApiException e2) { - messages.addAll(e2.messages); - if (e == null) { - e = e2.e; - } - } - - public boolean isInternalError() { - return e != null; - } - - public void format(PrintWriter out, Language language) { - out.println("
"); - if (isInternalError()) { - e.printStackTrace(); - out.print("
"); - out.println(language.getTranslation("An internal error ouccured.")); - out.println("
"); - } - for (String message : messages) { - out.print("
"); - out.print(language.getTranslation(message)); - out.println("
"); - } - out.println("
"); - - } - - public boolean isEmpty() { - return e == null && messages.size() == 0; - } + + private SQLException e; + + private LinkedList messages = new LinkedList<>(); + + public GigiApiException(SQLException e) { + super(e); + this.e = e; + } + + public GigiApiException(String message) { + super(message); + messages.add(message); + } + + public GigiApiException() { + + } + + public void mergeInto(GigiApiException e2) { + messages.addAll(e2.messages); + if (e == null) { + e = e2.e; + } + } + + public boolean isInternalError() { + return e != null; + } + + public void format(PrintWriter out, Language language) { + out.println("
"); + if (isInternalError()) { + e.printStackTrace(); + out.print("
"); + out.println(language.getTranslation("An internal error ouccured.")); + out.println("
"); + } + for (String message : messages) { + out.print("
"); + out.print(language.getTranslation(message)); + out.println("
"); + } + out.println("
"); + + } + + public boolean isEmpty() { + return e == null && messages.size() == 0; + } + + @Override + public String getMessage() { + if (messages.size() != 0) { + StringBuffer res = new StringBuffer(); + for (String string : messages) { + res.append(string + "\n"); + } + return res.toString(); + } + return ""; + } }