001    package com.thetransactioncompany.jsonrpc2.client;
002    
003    
004    /**
005     * Thrown to indicate a JSON-RPC 2.0 client session exception. Allows a general
006     * cause type to be specified to ease diagnostics and exception reporting.
007     *
008     * @author Vladimir Dzhuvinov
009     */
010    public class JSONRPC2SessionException extends Exception {
011    
012            
013            /**
014             * Unspecified cause type.
015             */
016            public static final int UNSPECIFIED = 0;
017    
018            
019            /**
020             * The exception cause is network or I/O related.
021             */
022            public static final int NETWORK_EXCEPTION = 1;
023            
024            
025            /**
026             * Unexpected "Content-Type" header value of the HTTP response.
027             */
028            public static final int UNEXPECTED_CONTENT_TYPE = 2;
029            
030            
031            /**
032             * Invalid JSON-RPC 2.0 response (invalid JSON or invalid JSON-RPC 2.0
033             * response message).
034             */
035            public static final int BAD_RESPONSE = 3;
036            
037            
038            /**
039             * Unexpected JSON-RPC 2.0 response result (the result doesn't match the
040             * JSON type / format expected by the client).
041             */
042            public static final int UNEXPECTED_RESULT = 4;
043            
044            
045            /**
046             * Received a JSON-RPC 2.0 error response.
047             */
048            public static final int JSONRPC2_ERROR = 5;
049            
050            
051            /**
052             * Indicates the type of cause for this exception, see
053             * constants.
054             */
055            private int causeType;
056            
057            
058            /**
059             * Creates a new JSON-RPC 2.0 session exception with the specified 
060             * message; the cause type is {@link #UNSPECIFIED}.
061             *
062             * @param message The message.
063             */
064            public JSONRPC2SessionException(final String message) {
065            
066                    super(message);
067                    causeType = UNSPECIFIED;
068            }
069            
070            
071            /**
072             * Creates a new JSON-RPC 2.0 session exception with the specified 
073             * message and cause type.
074             *
075             * @param message   The message.
076             * @param causeType The cause type, see the constants.
077             */
078            public JSONRPC2SessionException(final String message, final int causeType) {
079            
080                    super(message);
081                    this.causeType = causeType;
082            }
083            
084            
085            /**
086             * Creates a new JSON-RPC 2.0 session exception with the specified 
087             * message, cause type and cause.
088             *
089             * @param message   The message.
090             * @param causeType The cause type, see the constants.
091             * @param cause     The original exception.
092             */
093            public JSONRPC2SessionException(final String message, final int causeType, final Throwable cause) {
094            
095                    super(message, cause);
096                    this.causeType = causeType;
097            }
098            
099            
100            /**
101             * Returns the exception cause type.
102             *
103             * @return The cause type constant.
104             */
105            public int getCauseType() {
106            
107                    return causeType;
108            }
109    }