• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.emailcommon.mail;
18 
19 
20 /**
21  * This exception is used for most types of failures that occur during server interactions.
22  *
23  * Data passed through this exception should be considered non-localized.  Any strings should
24  * either be internal-only (for debugging) or server-generated.
25  *
26  * TO DO: Does it make sense to further collapse AuthenticationFailedException and
27  * CertificateValidationException and any others into this?
28  */
29 public class MessagingException extends Exception {
30     public static final long serialVersionUID = -1;
31 
32     public static final int NO_ERROR = -1;
33     /** Any exception that does not specify a specific issue */
34     public static final int UNSPECIFIED_EXCEPTION = 0;
35     /** Connection or IO errors */
36     public static final int IOERROR = 1;
37     /** The configuration requested TLS but the server did not support it. */
38     public static final int TLS_REQUIRED = 2;
39     /** Authentication is required but the server did not support it. */
40     public static final int AUTH_REQUIRED = 3;
41     /** General security failures */
42     public static final int GENERAL_SECURITY = 4;
43     /** Authentication failed */
44     public static final int AUTHENTICATION_FAILED = 5;
45     /** Attempt to create duplicate account */
46     public static final int DUPLICATE_ACCOUNT = 6;
47     /** Required security policies reported - advisory only */
48     public static final int SECURITY_POLICIES_REQUIRED = 7;
49    /** Required security policies not supported */
50     public static final int SECURITY_POLICIES_UNSUPPORTED = 8;
51    /** The protocol (or protocol version) isn't supported */
52     public static final int PROTOCOL_VERSION_UNSUPPORTED = 9;
53     /** The server's SSL certificate couldn't be validated */
54     public static final int CERTIFICATE_VALIDATION_ERROR = 10;
55     /** Authentication failed during autodiscover */
56     public static final int AUTODISCOVER_AUTHENTICATION_FAILED = 11;
57     /** Autodiscover completed with a result (non-error) */
58     public static final int AUTODISCOVER_AUTHENTICATION_RESULT = 12;
59     /** Ambiguous failure; server error or bad credentials */
60     public static final int AUTHENTICATION_FAILED_OR_SERVER_ERROR = 13;
61     /** The server refused access */
62     public static final int ACCESS_DENIED = 14;
63     /** The server refused access */
64     public static final int ATTACHMENT_NOT_FOUND = 15;
65     /** A client SSL certificate is required for connections to the server */
66     public static final int CLIENT_CERTIFICATE_REQUIRED = 16;
67     /** The client SSL certificate specified is invalid */
68     public static final int CLIENT_CERTIFICATE_ERROR = 17;
69 
70     protected int mExceptionType;
71     // Exception type-specific data
72     protected Object mExceptionData;
73 
MessagingException(String message, Throwable throwable)74     public MessagingException(String message, Throwable throwable) {
75         this(UNSPECIFIED_EXCEPTION, message, throwable);
76     }
77 
MessagingException(int exceptionType, String message, Throwable throwable)78     public MessagingException(int exceptionType, String message, Throwable throwable) {
79         super(message, throwable);
80         mExceptionType = exceptionType;
81         mExceptionData = null;
82     }
83 
84     /**
85      * Constructs a MessagingException with an exceptionType and a null message.
86      * @param exceptionType The exception type to set for this exception.
87      */
MessagingException(int exceptionType)88     public MessagingException(int exceptionType) {
89         this(exceptionType, null, null);
90     }
91 
92     /**
93      * Constructs a MessagingException with a message.
94      * @param message the message for this exception
95      */
MessagingException(String message)96     public MessagingException(String message) {
97         this(UNSPECIFIED_EXCEPTION, message, null);
98     }
99 
100     /**
101      * Constructs a MessagingException with an exceptionType and a message.
102      * @param exceptionType The exception type to set for this exception.
103      */
MessagingException(int exceptionType, String message)104     public MessagingException(int exceptionType, String message) {
105         this(exceptionType, message, null);
106     }
107 
108     /**
109      * Constructs a MessagingException with an exceptionType, a message, and data
110      * @param exceptionType The exception type to set for this exception.
111      * @param message the message for the exception (or null)
112      * @param data exception-type specific data for the exception (or null)
113      */
MessagingException(int exceptionType, String message, Object data)114     public MessagingException(int exceptionType, String message, Object data) {
115         super(message);
116         mExceptionType = exceptionType;
117         mExceptionData = data;
118     }
119 
120     /**
121      * Return the exception type.  Will be OTHER_EXCEPTION if not explicitly set.
122      *
123      * @return Returns the exception type.
124      */
getExceptionType()125     public int getExceptionType() {
126         return mExceptionType;
127     }
128     /**
129      * Return the exception data.  Will be null if not explicitly set.
130      *
131      * @return Returns the exception data.
132      */
getExceptionData()133     public Object getExceptionData() {
134         return mExceptionData;
135     }
136 }