1 /*
  2  * ***** BEGIN LICENSE BLOCK *****
  3  * Zimbra Collaboration Suite Web Client
  4  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Synacor, Inc.
  5  *
  6  * The contents of this file are subject to the Common Public Attribution License Version 1.0 (the "License");
  7  * you may not use this file except in compliance with the License.
  8  * You may obtain a copy of the License at: https://www.zimbra.com/license
  9  * The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15
 10  * have been added to cover use of software over a computer network and provide for limited attribution
 11  * for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B.
 12  *
 13  * Software distributed under the License is distributed on an "AS IS" basis,
 14  * WITHOUT WARRANTY OF ANY KIND, either express or implied.
 15  * See the License for the specific language governing rights and limitations under the License.
 16  * The Original Code is Zimbra Open Source Web Client.
 17  * The Initial Developer of the Original Code is Zimbra, Inc.  All rights to the Original Code were
 18  * transferred by Zimbra, Inc. to Synacor, Inc. on September 14, 2015.
 19  *
 20  * All portions of the code are Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Synacor, Inc. All Rights Reserved.
 21  * ***** END LICENSE BLOCK *****
 22  */
 23 
 24 /**
 25  * @overview
 26  * This file contains the exception class.
 27  */
 28 /**
 29  * Creates an exception.
 30  * @class
 31  * This class represents an exception returned by the server as a response, generally as a fault. The fault
 32  * data is converted to properties of the exception.
 33  *
 34  * @param {Hash}	params	a hash of parameters
 35  * @param {String}      params.msg		the explanation (Fault.Reason.Text)
 36  * @param {String}      params.code		the error code (Fault.Detail.Error.Code)
 37  * @param {String}      params.method	the request name
 38  * @param {String}      params.detail	the Fault.Code.Value
 39  * @param {Object}      [params.data]		an optional structured fault data (Fault.Detail.Error.a)
 40  * @param {String}      params.trace		the trace info (Fault.Detail.Error.Trace)
 41  * @param {String}       params.request	the SOAP or JSON that represents the request
 42  * 
 43  * @extends		AjxException
 44  */
 45 ZmCsfeException = function(params) {
 46 
 47 	params = Dwt.getParams(arguments, ZmCsfeException.PARAMS);
 48 
 49 	AjxException.call(this, params.msg, params.code, params.method, params.detail);
 50 	
 51 	if (params.data) {
 52 		this.data = {};
 53 		for (var i = 0; i < params.data.length; i++) {
 54 			var item = params.data[i];
 55 			var key = item.n;
 56 			if (!this.data[key]) {
 57 				this.data[key] = [];
 58 			}
 59 			this.data[key].push(item._content);
 60 		}
 61 	}
 62 	
 63 	this.trace = params.trace;
 64 	this.request = params.request;
 65 };
 66 
 67 ZmCsfeException.PARAMS = ["msg", "code", "method", "detail", "data", "trace"];
 68 
 69 ZmCsfeException.prototype = new AjxException;
 70 ZmCsfeException.prototype.constructor = ZmCsfeException;
 71 ZmCsfeException.prototype.isZmCsfeException = true;
 72 
 73 /**
 74  * Returns a string representation of the object.
 75  * 
 76  * @return		{String}		a string representation of the object
 77  */
 78 ZmCsfeException.prototype.toString =
 79 function() {
 80 	return "ZmCsfeException";
 81 };
 82 
 83 //
 84 // Constants
 85 //
 86 
 87 // structured data keys
 88 ZmCsfeException.MAIL_SEND_ADDRESS_FAILURE_INVALID = "invalid";
 89 ZmCsfeException.MAIL_SEND_ADDRESS_FAILURE_UNSENT = "unsent";
 90 
 91 //
 92 // Static functions
 93 //
 94 
 95 /**
 96  * Gets the error messages.
 97  * 
 98  * @param	{String}	code	the code
 99  * @param	{Array}	args		the message format args
100  * 
101  * @return	{String}	the message
102  */
103 ZmCsfeException.getErrorMsg =
104 function(code, args) {
105 	var msg = ZMsg[code];
106 	if (!msg) {
107 		ZmCsfeException._unknownFormat = ZmCsfeException._unknownFormat || new AjxMessageFormat(ZMsg.unknownError);
108 		return ZmCsfeException._unknownFormat.format(code);
109 	}
110 	this.msg = this.msg || msg;
111 	return args ? AjxMessageFormat.format(msg, args) : msg;
112 };
113 
114 //
115 // Public methods
116 //
117 
118 /**
119  * Gets the error message.
120  * 
121  * @param	{Array}	args		the message format args
122  * @return	{String}	the message
123  */
124 ZmCsfeException.prototype.getErrorMsg =
125 function(args) {
126 	return ZmCsfeException.getErrorMsg(this.code, args);
127 };
128 
129 /**
130  * Gets the data.
131  * 
132  * @param	{Object}	key		the key
133  * 
134  * @return	{Object}	the data
135  */
136 ZmCsfeException.prototype.getData =
137 function(key) {
138 	return this.data && this.data[key];
139 };
140 
141 //
142 // Constants for server exceptions
143 //
144 
145 ZmCsfeException.AUTH_TOKEN_CHANGED					= "AUTH_TOKEN_CHANGED";
146 ZmCsfeException.BAD_JSON_RESPONSE					= "BAD_JSON_RESPONSE";
147 ZmCsfeException.CSFE_SVC_ERROR						= "CSFE_SVC_ERROR";
148 ZmCsfeException.EMPTY_RESPONSE						= "EMPTY_RESPONSE";
149 ZmCsfeException.NETWORK_ERROR						= "NETWORK_ERROR";
150 ZmCsfeException.NO_AUTH_TOKEN						= "NO_AUTH_TOKEN";
151 ZmCsfeException.SOAP_ERROR							= "SOAP_ERROR";
152 
153 ZmCsfeException.LICENSE_ERROR						= "service.LICENSE_ERROR";
154 ZmCsfeException.SVC_ALREADY_IN_PROGRESS				= "service.ALREADY_IN_PROGRESS";
155 ZmCsfeException.SVC_AUTH_EXPIRED					= "service.AUTH_EXPIRED";
156 ZmCsfeException.SVC_AUTH_REQUIRED					= "service.AUTH_REQUIRED";
157 ZmCsfeException.SVC_FAILURE							= "service.FAILURE";
158 ZmCsfeException.SVC_INVALID_REQUEST					= "service.INVALID_REQUEST";
159 ZmCsfeException.SVC_PARSE_ERROR						= "service.PARSE_ERROR";
160 ZmCsfeException.SVC_PERM_DENIED						= "service.PERM_DENIED";
161 ZmCsfeException.SVC_RESOURCE_UNREACHABLE			= "service.RESOURCE_UNREACHABLE";
162 ZmCsfeException.SVC_UNKNOWN_DOCUMENT				= "service.UNKNOWN_DOCUMENT";
163 ZmCsfeException.SVC_TEMPORARILY_UNAVAILABLE			= "service.TEMPORARILY_UNAVAILABLE";
164 ZmCsfeException.SVC_WRONG_HOST						= "service.WRONG_HOST";
165 
166 ZmCsfeException.ACCT_AUTH_FAILED					= "account.AUTH_FAILED";
167 ZmCsfeException.ACCT_CHANGE_PASSWORD				= "account.CHANGE_PASSWORD";
168 ZmCsfeException.ACCT_EXISTS							= "account.ACCOUNT_EXISTS";
169 ZmCsfeException.ACCT_TOO_MANY_ACCOUNTS      		= "account.TOO_MANY_ACCOUNTS" ;
170 ZmCsfeException.ACCT_INVALID_ATTR_VALUE				= "account.INVALID_ATTR_VALUE";
171 ZmCsfeException.ACCT_INVALID_PASSWORD				= "account.INVALID_PASSWORD";
172 ZmCsfeException.ACCT_INVALID_PREF_NAME				= "account.INVALID_PREF_NAME";
173 ZmCsfeException.ACCT_INVALID_PREF_VALUE				= "account.INVALID_PREF_VALUE";
174 ZmCsfeException.ACCT_MAINTENANCE_MODE				= "account.MAINTENANCE_MODE";
175 ZmCsfeException.ACCT_NO_SUCH_ACCOUNT				= "account.NO_SUCH_ACCOUNT";
176 ZmCsfeException.ACCT_NO_SUCH_SAVED_SEARCH			= "account.NO_SUCH_SAVED_SEARCH";
177 ZmCsfeException.ACCT_NO_SUCH_TAG					= "account.ACCT_NO_SUCH_TAG";
178 ZmCsfeException.ACCT_PASS_CHANGE_TOO_SOON			= "account.PASSWORD_CHANGE_TOO_SOON";
179 ZmCsfeException.ACCT_PASS_LOCKED					= "account.PASSWORD_LOCKED";
180 ZmCsfeException.ACCT_PASS_RECENTLY_USED				= "account.PASSWORD_RECENTLY_USED";
181 ZmCsfeException.COS_EXISTS							= "account.COS_EXISTS";
182 ZmCsfeException.DISTRIBUTION_LIST_EXISTS			= "account.DISTRIBUTION_LIST_EXISTS";
183 ZmCsfeException.DOMAIN_EXISTS						= "account.DOMAIN_EXISTS";
184 ZmCsfeException.DOMAIN_NOT_EMPTY					= "account.DOMAIN_NOT_EMPTY";
185 ZmCsfeException.IDENTITY_EXISTS						= "account.IDENTITY_EXISTS";
186 ZmCsfeException.NO_SUCH_DISTRIBUTION_LIST			= "account.NO_SUCH_DISTRIBUTION_LIST";
187 ZmCsfeException.NO_SUCH_DOMAIN						= "account.NO_SUCH_DOMAIN";
188 ZmCsfeException.MAINTENANCE_MODE					= "account.MAINTENANCE_MODE";
189 ZmCsfeException.TOO_MANY_IDENTITIES					= "account.TOO_MANY_IDENTITIES";
190 ZmCsfeException.TOO_MANY_SEARCH_RESULTS				= "account.TOO_MANY_SEARCH_RESULTS";
191 ZmCsfeException.NO_SUCH_COS 						= "account.NO_SUCH_COS";
192 ZmCsfeException.SIGNATURE_EXISTS                    = "account.SIGNATURE_EXISTS";
193 
194 ZmCsfeException.CANNOT_CHANGE_VOLUME = "volume.CANNOT_CHANGE_TYPE_OF_CURRVOL";
195 ZmCsfeException.CANNOT_DELETE_VOLUME_IN_USE = "volume.CANNOT_DELETE_VOLUME_IN_USE";
196 ZmCsfeException.NO_SUCH_VOLUME						= "volume.NO_SUCH_VOLUME";
197 ZmCsfeException.ALREADY_EXISTS						= "volume.ALREADY_EXISTS";
198 ZmCsfeException.VOLUME_NO_SUCH_PATH					= "volume.NO_SUCH_PATH";
199 
200 ZmCsfeException.MAIL_ALREADY_EXISTS					= "mail.ALREADY_EXISTS";
201 ZmCsfeException.MAIL_IMMUTABLE						= "mail.IMMUTABLE_OBJECT";
202 ZmCsfeException.MAIL_INVALID_NAME					= "mail.INVALID_NAME";
203 ZmCsfeException.MAIL_INVITE_OUT_OF_DATE				= "mail.INVITE_OUT_OF_DATE";
204 ZmCsfeException.MAIL_MAINTENANCE_MODE				= "mail.MAINTENANCE";
205 ZmCsfeException.MAIL_MESSAGE_TOO_BIG				= "mail.MESSAGE_TOO_BIG";
206 ZmCsfeException.MAIL_MUST_RESYNC					= "mail.MUST_RESYNC";
207 ZmCsfeException.MAIL_NO_SUCH_CALITEM				= "mail.NO_SUCH_CALITEM";
208 ZmCsfeException.MAIL_NO_SUCH_CONV					= "mail.NO_SUCH_CONV";
209 ZmCsfeException.MAIL_NO_SUCH_CONTACT				= "mail.NO_SUCH_CONTACT";
210 ZmCsfeException.MAIL_NO_SUCH_FOLDER					= "mail.NO_SUCH_FOLDER";
211 ZmCsfeException.MAIL_NO_SUCH_ITEM					= "mail.NO_SUCH_ITEM";
212 ZmCsfeException.MAIL_NO_SUCH_MOUNTPOINT				= "mail.NO_SUCH_MOUNTPOINT";
213 ZmCsfeException.MAIL_NO_SUCH_MSG					= "mail.NO_SUCH_MSG";
214 ZmCsfeException.MAIL_NO_SUCH_PART					= "mail.NO_SUCH_PART";
215 ZmCsfeException.MAIL_NO_SUCH_TAG					= "mail.NO_SUCH_TAG";
216 ZmCsfeException.MAIL_QUERY_PARSE_ERROR				= "mail.QUERY_PARSE_ERROR";
217 ZmCsfeException.MAIL_QUOTA_EXCEEDED					= "mail.QUOTA_EXCEEDED";
218 ZmCsfeException.MAIL_SEND_ABORTED_ADDRESS_FAILURE	= "mail.SEND_ABORTED_ADDRESS_FAILURE";
219 ZmCsfeException.MAIL_SEND_FAILURE					= "mail.SEND_FAILURE";
220 ZmCsfeException.MAIL_TOO_MANY_CONTACTS				= "mail.TOO_MANY_CONTACTS";
221 ZmCsfeException.MAIL_TOO_MANY_TERMS					= "mail.TOO_MANY_QUERY_TERMS_EXPANDED";
222 ZmCsfeException.MAIL_UNABLE_TO_IMPORT_APPOINTMENTS	= "mail.MAIL_UNABLE_TO_IMPORT_APPOINTMENTS";
223 ZmCsfeException.MAIL_UNABLE_TO_IMPORT_CONTACTS		= "mail.UNABLE_TO_IMPORT_CONTACTS";
224 ZmCsfeException.MODIFY_CONFLICT						= "mail.MODIFY_CONFLICT";
225 ZmCsfeException.TOO_MANY_TAGS						= "mail.TOO_MANY_TAGS";
226 ZmCsfeException.CANNOT_RENAME                       = "mail.CANNOT_RENAME";
227 ZmCsfeException.CANNOT_UNLOCK                       = "mail.CANNOT_UNLOCK";
228 ZmCsfeException.CANNOT_LOCK                         = "mail.CANNOT_LOCK";
229 ZmCsfeException.LOCKED                              = "mail.LOCKED";
230 ZmCsfeException.UPLOAD_REJECTED						= "mail.UPLOAD_REJECTED";
231 
232 ZmCsfeException.MUST_BE_ORGANIZER					= "mail.MUST_BE_ORGANIZER";
233 
234 
235 ZmCsfeException.OFFLINE_ONLINE_ONLY_OP				= "offline.ONLINE_ONLY_OP";
236