1 /* 2 * Copyright (C) 2015 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.voicemail.impl.mail; 18 19 /** 20 * This exception is used for most types of failures that occur during server interactions. 21 * 22 * <p>Data passed through this exception should be considered non-localized. Any strings should 23 * either be internal-only (for debugging) or server-generated. 24 * 25 * <p>TO DO: Does it make sense to further collapse AuthenticationFailedException and 26 * CertificateValidationException and any others into this? 27 */ 28 public class MessagingException extends Exception { 29 public static final long serialVersionUID = -1; 30 31 public static final int NO_ERROR = -1; 32 /** Any exception that does not specify a specific issue */ 33 public static final int UNSPECIFIED_EXCEPTION = 0; 34 /** Connection or IO errors */ 35 public static final int IOERROR = 1; 36 /** The configuration requested TLS but the server did not support it. */ 37 public static final int TLS_REQUIRED = 2; 38 /** Authentication is required but the server did not support it. */ 39 public static final int AUTH_REQUIRED = 3; 40 /** General security failures */ 41 public static final int GENERAL_SECURITY = 4; 42 /** Authentication failed */ 43 public static final int AUTHENTICATION_FAILED = 5; 44 /** Attempt to create duplicate account */ 45 public static final int DUPLICATE_ACCOUNT = 6; 46 /** Required security policies reported - advisory only */ 47 public static final int SECURITY_POLICIES_REQUIRED = 7; 48 /** Required security policies not supported */ 49 public static final int SECURITY_POLICIES_UNSUPPORTED = 8; 50 /** The protocol (or protocol version) isn't supported */ 51 public static final int PROTOCOL_VERSION_UNSUPPORTED = 9; 52 /** The server's SSL certificate couldn't be validated */ 53 public static final int CERTIFICATE_VALIDATION_ERROR = 10; 54 /** Authentication failed during autodiscover */ 55 public static final int AUTODISCOVER_AUTHENTICATION_FAILED = 11; 56 /** Autodiscover completed with a result (non-error) */ 57 public static final int AUTODISCOVER_AUTHENTICATION_RESULT = 12; 58 /** Ambiguous failure; server error or bad credentials */ 59 public static final int AUTHENTICATION_FAILED_OR_SERVER_ERROR = 13; 60 /** The server refused access */ 61 public static final int ACCESS_DENIED = 14; 62 /** The server refused access */ 63 public static final int ATTACHMENT_NOT_FOUND = 15; 64 /** A client SSL certificate is required for connections to the server */ 65 public static final int CLIENT_CERTIFICATE_REQUIRED = 16; 66 /** The client SSL certificate specified is invalid */ 67 public static final int CLIENT_CERTIFICATE_ERROR = 17; 68 /** The server indicates it does not support OAuth authentication */ 69 public static final int OAUTH_NOT_SUPPORTED = 18; 70 /** The server indicates it experienced an internal error */ 71 public static final int SERVER_ERROR = 19; 72 73 protected int exceptionType; 74 // Exception type-specific data 75 protected Object exceptionData; 76 MessagingException(String message, Throwable throwable)77 public MessagingException(String message, Throwable throwable) { 78 this(UNSPECIFIED_EXCEPTION, message, throwable); 79 } 80 MessagingException(int exceptionType, String message, Throwable throwable)81 public MessagingException(int exceptionType, String message, Throwable throwable) { 82 super(message, throwable); 83 this.exceptionType = exceptionType; 84 exceptionData = null; 85 } 86 87 /** 88 * Constructs a MessagingException with an exceptionType and a null message. 89 * 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 * 99 * @param message the message for this exception 100 */ MessagingException(String message)101 public MessagingException(String message) { 102 this(UNSPECIFIED_EXCEPTION, message, null); 103 } 104 105 /** 106 * Constructs a MessagingException with an exceptionType and a message. 107 * 108 * @param exceptionType The exception type to set for this exception. 109 */ MessagingException(int exceptionType, String message)110 public MessagingException(int exceptionType, String message) { 111 this(exceptionType, message, null); 112 } 113 114 /** 115 * Constructs a MessagingException with an exceptionType, a message, and data 116 * 117 * @param exceptionType The exception type to set for this exception. 118 * @param message the message for the exception (or null) 119 * @param data exception-type specific data for the exception (or null) 120 */ MessagingException(int exceptionType, String message, Object data)121 public MessagingException(int exceptionType, String message, Object data) { 122 super(message); 123 this.exceptionType = exceptionType; 124 exceptionData = data; 125 } 126 127 /** 128 * Return the exception type. Will be OTHER_EXCEPTION if not explicitly set. 129 * 130 * @return Returns the exception type. 131 */ getExceptionType()132 public int getExceptionType() { 133 return exceptionType; 134 } 135 /** 136 * Return the exception data. Will be null if not explicitly set. 137 * 138 * @return Returns the exception data. 139 */ getExceptionData()140 public Object getExceptionData() { 141 return exceptionData; 142 } 143 } 144