MessagingException.java revision b46db2e400ab2eae168baea4c4c7a298cdfa4fb6
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
17package 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 */
29public 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    /** The server indicates it does not support OAuth authentication */
70    public static final int OAUTH_NOT_SUPPORTED = 18;
71
72    protected int mExceptionType;
73    // Exception type-specific data
74    protected Object mExceptionData;
75
76    public MessagingException(String message, Throwable throwable) {
77        this(UNSPECIFIED_EXCEPTION, message, throwable);
78    }
79
80    public MessagingException(int exceptionType, String message, Throwable throwable) {
81        super(message, throwable);
82        mExceptionType = exceptionType;
83        mExceptionData = null;
84    }
85
86    /**
87     * Constructs a MessagingException with an exceptionType and a null message.
88     * @param exceptionType The exception type to set for this exception.
89     */
90    public MessagingException(int exceptionType) {
91        this(exceptionType, null, null);
92    }
93
94    /**
95     * Constructs a MessagingException with a message.
96     * @param message the message for this exception
97     */
98    public MessagingException(String message) {
99        this(UNSPECIFIED_EXCEPTION, message, null);
100    }
101
102    /**
103     * Constructs a MessagingException with an exceptionType and a message.
104     * @param exceptionType The exception type to set for this exception.
105     */
106    public MessagingException(int exceptionType, String message) {
107        this(exceptionType, message, null);
108    }
109
110    /**
111     * Constructs a MessagingException with an exceptionType, a message, and data
112     * @param exceptionType The exception type to set for this exception.
113     * @param message the message for the exception (or null)
114     * @param data exception-type specific data for the exception (or null)
115     */
116    public MessagingException(int exceptionType, String message, Object data) {
117        super(message);
118        mExceptionType = exceptionType;
119        mExceptionData = data;
120    }
121
122    /**
123     * Return the exception type.  Will be OTHER_EXCEPTION if not explicitly set.
124     *
125     * @return Returns the exception type.
126     */
127    public int getExceptionType() {
128        return mExceptionType;
129    }
130    /**
131     * Return the exception data.  Will be null if not explicitly set.
132     *
133     * @return Returns the exception data.
134     */
135    public Object getExceptionData() {
136        return mExceptionData;
137    }
138}