summaryrefslogtreecommitdiffstats
path: root/src/main/java/is/cep/cepis/CepisException.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/is/cep/cepis/CepisException.java')
-rw-r--r--src/main/java/is/cep/cepis/CepisException.java49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/main/java/is/cep/cepis/CepisException.java b/src/main/java/is/cep/cepis/CepisException.java
new file mode 100644
index 0000000..8dbcdcb
--- /dev/null
+++ b/src/main/java/is/cep/cepis/CepisException.java
@@ -0,0 +1,49 @@
+package is.cep.cepis;
+
+/**
+ * The base of every error this library raises. Catch it to handle any failure.
+ *
+ * <p>Below it, the split is by <b>the decision the caller has to make</b>, not
+ * by the HTTP status that caused it:
+ *
+ * <ul>
+ * <li>{@link InvalidCepException} and {@link CepNotFoundException} are
+ * problems with the <i>request</i>. Retrying is pointless — the same CEP
+ * will fail again.</li>
+ * <li>{@link NetworkException}, {@link ServerErrorException} and
+ * {@link RateLimitedException} are problems with <i>transport</i>.
+ * Retrying may help, and the client already retried on its own before
+ * raising any of them.</li>
+ * <li>{@link InvalidResponseException} means a success status came back with
+ * a body nobody can read.</li>
+ * </ul>
+ *
+ * <p>These are unchecked. Java allows one superclass, and a single base that
+ * catches everything is worth more than each error also being an
+ * {@link IllegalArgumentException} or a {@link java.util.NoSuchElementException};
+ * a checked hierarchy would additionally put {@code throws} on every call site
+ * that only ever looks a CEP up.
+ */
+public class CepisException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Create the exception.
+ *
+ * @param message what went wrong
+ */
+ public CepisException(String message) {
+ super(message);
+ }
+
+ /**
+ * Create the exception with an underlying cause.
+ *
+ * @param message what went wrong
+ * @param cause the failure behind it, possibly {@code null}
+ */
+ public CepisException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}