1 /*
  2  * Copyright ©2012 SARA bv, The Netherlands
  3  *
  4  * This file is part of js-webdav-client.
  5  *
  6  * js-webdav-client is free software: you can redistribute it and/or modify
  7  * it under the terms of the GNU Lesser General Public License as published
  8  * by the Free Software Foundation, either version 3 of the License, or
  9  * (at your option) any later version.
 10  *
 11  * js-webdav-client is distributed in the hope that it will be useful,
 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 14  * GNU Lesser General Public License for more details.
 15  *
 16  * You should have received a copy of the GNU Lesser General Public License
 17  * along with js-webdav-client.  If not, see <http://www.gnu.org/licenses/>.
 18  */
 19 "use strict";
 20 
 21 // If nl.sara.webdav.Exception is already defined, we have a namespace clash!
 22 if (nl.sara.webdav.Exception !== undefined) {
 23   throw 'Class name nl.sara.webdav.Exception already taken, could not load JavaScript library for WebDAV connectivity.';
 24 }
 25 
 26 /**
 27  * @class An exception
 28  * @param  {String}  [message]  Optional; A human readable message
 29  * @param  {Number}  [code]     Optional; The error code. It is best to use the class constants to set this.
 30  * @property  {String}  message  The exception message
 31  * @property  {Number}  code     The exception code
 32  */
 33 nl.sara.webdav.Exception = function(message, code) {
 34   // First define public attributes
 35   Object.defineProperty(this, 'message', {
 36     'value': null,
 37     'enumerable': true,
 38     'configurable': false,
 39     'writable': true
 40   });
 41   Object.defineProperty(this, 'code', {
 42     'value': null,
 43     'enumerable': true,
 44     'configurable': false,
 45     'writable': true
 46   });
 47 
 48   // Constructor logic
 49   if (message !== undefined) {
 50     this.message = message;
 51   }
 52   if (code !== undefined) {
 53     this.code = code;
 54   }
 55 };
 56 
 57 /**#@+
 58  * Declaration of the error code constants
 59  */
 60 nl.sara.webdav.Exception.WRONG_TYPE = 1;
 61 nl.sara.webdav.Exception.NAMESPACE_TAKEN = 2;
 62 nl.sara.webdav.Exception.UNEXISTING_PROPERTY = 3;
 63 nl.sara.webdav.Exception.WRONG_XML = 4;
 64 nl.sara.webdav.Exception.WRONG_VALUE = 5;
 65 nl.sara.webdav.Exception.MISSING_REQUIRED_PARAMETER = 6;
 66 nl.sara.webdav.Exception.AJAX_ERROR = 7;
 67 nl.sara.webdav.Exception.NOT_IMPLEMENTED = 8;
 68 /**#@-*/
 69 
 70 //########################## DEFINE PUBLIC METHODS #############################
 71 /**
 72  * Overloads the default toString() method so it returns the message of this exception
 73  *
 74  * @returns  {String}  A string representation of this property
 75  */
 76 nl.sara.webdav.Exception.prototype.toString = function() {
 77   return this.message;
 78 };
 79 
 80 // End of library
 81