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