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.
This commit is contained in:
parent
e6251687bf
commit
3edd727a94
1 changed files with 21 additions and 15 deletions
|
@ -1,17 +1,23 @@
|
||||||
/*
|
/**
|
||||||
This helper modules allows us to create different type of errors we can throw
|
* CustomError
|
||||||
*/
|
*
|
||||||
function customError(message, errorName)
|
* This helper modules allows us to create different type of errors we can throw
|
||||||
{
|
*
|
||||||
this.name = errorName || "Error";
|
* @class CustomError
|
||||||
this.message = message;
|
* @extends {Error}
|
||||||
|
*/
|
||||||
var stackParts = new Error().stack.split("\n");
|
class CustomError extends Error {
|
||||||
stackParts.splice(0,2);
|
/**
|
||||||
stackParts.unshift(this.name + ": " + message);
|
* Creates an instance of CustomError.
|
||||||
|
* @param {*} message
|
||||||
this.stack = stackParts.join("\n");
|
* @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;
|
||||||
|
|
Loading…
Reference in a new issue