From 3edd727a943cfa94bb200c8d7d743e1ecce31f58 Mon Sep 17 00:00:00 2001 From: Viljami Kuosmanen Date: Mon, 6 Apr 2020 19:12:15 +0200 Subject: [PATCH] customError: rewrite the module using class syntax The previous syntax caused a deprecation warning on Node 10. However, due to the very old version of log4js Etherpad is currently using, customError objects are going to be displayed as { inspect: [Function: inspect] }. This needs to be addressed later, updating log4js. Fixes #3834. --- src/node/utils/customError.js | 36 ++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/node/utils/customError.js b/src/node/utils/customError.js index c18743485..c47729f7f 100644 --- a/src/node/utils/customError.js +++ b/src/node/utils/customError.js @@ -1,17 +1,23 @@ -/* - This helper modules allows us to create different type of errors we can throw -*/ -function customError(message, errorName) -{ - this.name = errorName || "Error"; - this.message = message; - - var stackParts = new Error().stack.split("\n"); - stackParts.splice(0,2); - stackParts.unshift(this.name + ": " + message); - - this.stack = stackParts.join("\n"); +/** + * CustomError + * + * This helper modules allows us to create different type of errors we can throw + * + * @class CustomError + * @extends {Error} + */ +class CustomError extends Error { + /** + * Creates an instance of CustomError. + * @param {*} message + * @param {string} [name='Error'] a custom name for the error object + * @memberof CustomError + */ + constructor(message, name = 'Error') { + super(message); + this.name = name; + Error.captureStackTrace(this, this.constructor); + } } -customError.prototype = Error.prototype; -module.exports = customError; +module.exports = CustomError;