1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2005, 2006, 2007, 2009, 2010, 2013, 2014, 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) 2005, 2006, 2007, 2009, 2010, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * Creates an exception. 26 * @constructor 27 * @class 28 * This is the base class for all exceptions in the Zimbra Ajax Toolkit. 29 * 30 * @author Ross Dargahi 31 * 32 * @param {string} [msg] the human readable message 33 * @param {constant} [code] any error or fault code 34 * @param {string} [method] the name of the method throwing the exception 35 * @param {string} [detail] any additional detail 36 */ 37 AjxException = function(msg, code, method, detail) { 38 39 if (arguments.length == 0) { return; } 40 41 /** 42 * Human readable message, if applicable. 43 */ 44 this.msg = msg; 45 46 /** 47 * Error or fault code, if applicable. 48 */ 49 this.code = code; 50 51 /** 52 * Name of the method throwing the exception, if applicable. 53 */ 54 this.method = method; 55 56 /** 57 * Any additional detail. 58 */ 59 this.detail = detail; 60 }; 61 62 /** 63 * Returns a string representation of the object. 64 * 65 * @return {string} a string representation of the object 66 */ 67 AjxException.prototype.toString = 68 function() { 69 return "AjxException"; 70 }; 71 72 /** 73 * Dumps the exception. 74 * 75 * @return {string} the state of the exception 76 */ 77 AjxException.prototype.dump = 78 function() { 79 return "AjxException: msg=" + this.msg + " code=" + this.code + " method=" + this.method + " detail=" + this.detail; 80 }; 81 82 /** 83 * Invalid parent exception code. 84 */ 85 AjxException.INVALIDPARENT = "AjxException.INVALIDPARENT"; 86 87 /** 88 * Invalid operation exception code. 89 */ 90 AjxException.INVALID_OP = "AjxException.INVALID_OP"; 91 92 /** 93 * Internal error exception code. 94 */ 95 AjxException.INTERNAL_ERROR = "AjxException.INTERNAL_ERROR"; 96 97 /** 98 * Invalid parameter to method/operation exception code. 99 */ 100 AjxException.INVALID_PARAM = "AjxException.INVALID_PARAM"; 101 102 /** 103 * Unimplemented method called exception code. 104 */ 105 AjxException.UNIMPLEMENTED_METHOD = "AjxException.UNIMPLEMENTED_METHOD"; 106 107 /** 108 * Network error exception code. 109 */ 110 AjxException.NETWORK_ERROR = "AjxException.NETWORK_ERROR"; 111 112 /** 113 * Out or RPC cache exception code. 114 */ 115 AjxException.OUT_OF_RPC_CACHE = "AjxException.OUT_OF_RPC_CACHE"; 116 117 /** 118 * Unsupported operation code. 119 */ 120 AjxException.UNSUPPORTED = "AjxException.UNSUPPORTED"; 121 122 /** 123 * Unknown error exception code. 124 */ 125 AjxException.UNKNOWN_ERROR = "AjxException.UNKNOWN_ERROR"; 126 127 /** 128 * Operation canceled exception code. 129 */ 130 AjxException.CANCELED = "AjxException.CANCELED"; 131 132 AjxException.defaultScriptErrorHandler = 133 function(ex) { 134 alert(ex); 135 }; 136 137 AjxException.setScriptErrorHandler = 138 function(func) { 139 AjxException.scriptErrorHandler = func; 140 }; 141 142 AjxException.reportScriptError = 143 function(ex) { 144 if (AjxException.reportScriptErrors && AjxException.scriptErrorHandler && !(ex instanceof AjxException)) { 145 AjxException.scriptErrorHandler(ex); 146 } 147 throw ex; 148 }; 149 150 AjxException.reportScriptErrors = false; 151 AjxException.scriptErrorHandler = AjxException.defaultScriptErrorHandler; 152