geoportal-access-lib
Version:
French Geoportal resources access library
73 lines (67 loc) • 2.32 kB
JavaScript
/**
* Errors raised by API for one among three reasons : wrong API usage, underlying service error or unknown reason.
*
* @property {String} message - Error message
* @property {Number} status - Error status : when {@link Gp.Error.TYPE_SRVERR}, gives the [HTTP status of the underlying web service response]{@link https://en.wikipedia.org/wiki/List_of_HTTP_status_codes} ; -1 otherwise.
* @property {String} type - Error type ({@link Gp.Error.TYPE_SRVERR}, {@link Gp.Error.TYPE_USEERR} or {@link Gp.Error.TYPE_UNKERR}).
*
* @namespace
* @alias Gp.Error
* @param {Object|String} error - Options for creating error object. Can be a String (message) or an Object.
* @param {String} error.message - Error message to return to user.
* @param {enum} [error.type=TYPE_UNKERR] - Error type
* @param {status} [error.status=-1] - Error status : when {@link Gp.Error.TYPE_SRVERR}, gives the [HTTP status of the underlying web service response]{@link https://en.wikipedia.org/wiki/List_of_HTTP_status_codes}.
*
*/
function ErrorService (error) {
if (!(this instanceof ErrorService)) {
throw new TypeError("ErrorService constructor cannot be called as a function.");
}
var e = error;
if (typeof error === "string" || error instanceof String) {
this.message = error;
this.status = -1;
this.type = ErrorService.TYPE_UNKERR;
} else {
this.message = e.message || "undefined!?";
this.type = e.type;
this.status = e.status || -1;
}
this.name = "ErrorService";
this.stack = (new Error()).stack;
}
/**
* Error raised when underlying geoportal service answers on error.
*
* @type {String}
* @constant
* @static
*/
ErrorService.TYPE_SRVERR = "SERVICE_ERROR";
/**
* Error raised when funcion use is inappropriate
*
* @type {String}
* @constant
* @static
*/
ErrorService.TYPE_USEERR = "USAGE_ERROR";
/**
* Error raised when API can't perform the job for a reason other than the two other ones.
*
* @type {String}
* @constant
* @static
*/
ErrorService.TYPE_UNKERR = "UNKNOWN_ERROR";
/**
* @lends module:ErrorService
*/
ErrorService.prototype = Object.create(Error.prototype, {
constructor : {
value : ErrorService,
writable : true,
configurable : true
}
});
export default ErrorService;