public class GigiApiException extends Exception {
+ private static final Language PLAIN_LANGUAGE = Language.getInstance(Locale.ENGLISH);
+
private static final long serialVersionUID = -164928670180852588L;
private SQLException e;
}
+ public void formatPlain(PrintWriter out) {
+ if (isInternalError()) {
+ out.println(PLAIN_LANGUAGE.getTranslation("An internal error ouccured."));
+ }
+ HashMap<String, Object> map = new HashMap<>();
+ for (Outputable message : messages) {
+ if (message instanceof TranslateCommand) {
+ String m = ((TranslateCommand) message).getRaw();
+ // Skip HTML Entities
+ out.println(PLAIN_LANGUAGE.getTranslation(m));
+ } else {
+ map.clear();
+ message.output(out, PLAIN_LANGUAGE, map);
+ out.println();
+ }
+ }
+ }
+
public boolean isEmpty() {
return e == null && messages.size() == 0;
}
HashMap<String, Object> map = new HashMap<>();
for (Outputable message : messages) {
map.clear();
- message.output(pw, Language.getInstance(Locale.ENGLISH), map);
+ message.output(pw, PLAIN_LANGUAGE, map);
}
pw.flush();
package org.cacert.gigi.api;
import java.io.IOException;
+import java.io.PrintWriter;
import java.security.GeneralSecurityException;
import javax.servlet.http.HttpServletRequest;
resp.getWriter().println(PEM.encode("CERTIFICATE", result.cert().getEncoded()));
return;
} catch (GeneralSecurityException e) {
- e.printStackTrace();
+ resp.sendError(500, "Crypto failed");
} catch (GigiApiException e) {
- e.printStackTrace();
+ resp.setStatus(500);
+ PrintWriter wr = resp.getWriter();
+ e.formatPlain(wr);
} catch (InterruptedException e) {
- e.printStackTrace();
+ resp.sendError(500, "Interrupted");
}
}
}