package com.rollbar.payload.data.body;

import com.google.gson.annotations.SerializedName;
import com.rollbar.payload.utilities.ArgumentNullException;
import com.rollbar.payload.utilities.Validate;

public class ExceptionInfo {
    public static ExceptionInfo fromThrowable(Throwable error) throws ArgumentNullException {
        Validate.isNotNull(error, "error");
        String className = error.getClass().getSimpleName();
        String message = error.getMessage();
        return new ExceptionInfo(className, message, null);
    }

    @SerializedName("class")
    private final String className;
    private final String message;
    private final String description;


    public ExceptionInfo(String className) throws ArgumentNullException {
        this(className, null, null);
    }

    public ExceptionInfo(String className, String message, String description) throws ArgumentNullException {
        Validate.isNotNullOrWhitespace(className, "className");
        this.className = className;
        this.message = message;
        this.description = description;
    }

    public String className() {
        return this.className;
    }

    public ExceptionInfo className(String className) throws ArgumentNullException {
        return new ExceptionInfo(className, message, description);
    }

    public String message() {
        return this.message;
    }

    public ExceptionInfo message(String message) {
        try {
            return new ExceptionInfo(className, message, description);
        } catch (ArgumentNullException e) {
            throw new IllegalStateException("className shouldn't be null");
        }
    }

    public String description() {
        return this.description;
    }

    public ExceptionInfo description(String description) {
        try {
            return new ExceptionInfo(className, message, description);
        } catch (ArgumentNullException e) {
            throw new IllegalStateException("className shouldn't be null");
        }
    }
}

@@ -196,36 +196,377 @@
 e;%0A%0A
-public class ExceptionInfo %7B
+/**%0A * Represents *non-stacktrace* information about an exception, like class, description, and message.%0A */%0Apublic class ExceptionInfo %7B%0A    /**%0A     * Create an exception info from a throwable.%0A     * @param error the throwable%0A     * @return an exception info with information gathered from the error%0A     * @throws ArgumentNullException if the error is null%0A     */
 %0A   
@@ -1015,126 +1015,566 @@
 n;%0A%0A
-%0A    public ExceptionInfo(String className) throws ArgumentNullException %7B%0A        this(className, null, null);%0A    %7D%0A
+    /**%0A     * Constructor%0A     * @param className the name of the exception class%0A     * @throws ArgumentNullException if the name is null or whitespace%0A     */%0A    public ExceptionInfo(String className) throws ArgumentNullException %7B%0A        this(className, null, null);%0A    %7D%0A%0A    /**%0A     * Constructor%0A     * @param className the name of the exception class%0A     * @param message the exception message%0A     * @param description a human readable description of the exception%0A     * @throws ArgumentNullException if className is null or whitespace%0A     */
 %0A   
@@ -1851,32 +1851,95 @@
 ription;%0A    %7D%0A%0A
+    /**%0A     * @return the name of the exception class%0A     */%0A
     public Strin
@@ -1984,32 +1984,289 @@
 assName;%0A    %7D%0A%0A
+    /**%0A     * Set the className on a copy of this ExceptionInfo%0A     * @param className the new className%0A     * @return a copy of this ExceptionInfo with className overridden%0A     * @throws ArgumentNullException if className is null or whitespace%0A     */%0A
     public Excep
@@ -2399,32 +2399,85 @@
 iption);%0A    %7D%0A%0A
+    /**%0A     * @return the exception message%0A     */%0A
     public Strin
@@ -2534,276 +2534,382 @@
     
-public ExceptionInfo message(String message) %7B%0A        try %7B%0A            return new ExceptionInfo(className, message, description);%0A        %7D catch (ArgumentNullException e) %7B%0A            throw new IllegalStateException(%22className shouldn't be null%22);%0A        %7D%0A    %7D%0A
+/**%0A     * Set the message on a copy of this ExceptionInfo%0A     * @param message the new message%0A     * @return a copy of this ExceptionInfo with message overridden%0A     */%0A    public ExceptionInfo message(String message) %7B%0A        return new ExceptionInfo(className, message, description);%0A    %7D%0A%0A    /**%0A     * @return a human readable description of the exception%0A     */
 %0A   
@@ -2983,36 +2983,92 @@
  %7D%0A%0A    
-public ExceptionInfo
+/**%0A     * Set the description on a copy of this ExceptionInfo%0A     * @param
  descrip
@@ -3071,23 +3071,24 @@
 cription
-(String
+ the new
  descrip
@@ -3095,137 +3095,143 @@
 tion
-) %7B%0A        try %7B%0A            return new ExceptionInfo(className, message, description);%0A        %7D catch (ArgumentNullExce
+%0A     * @return a copy of this ExceptionInfo with description overriden%0A     */%0A    public ExceptionInfo description(String descri
 ption
- e
 ) %7B%0A
@@ -3242,34 +3242,19 @@
     
-    throw new IllegalState
+return new 
 Exce
@@ -3258,18 +3258,21 @@
 xception
+Info
 (
-%22
 classNam
@@ -3276,39 +3276,32 @@
 Name
- shouldn't be null%22);%0A        %7D
+, message, description);
 %0A   

Document ExceptionInfo and remove uneeded try/catches