Skip to content

Instantly share code, notes, and snippets.

@akshendra
Created June 9, 2017 11:11
Show Gist options
  • Save akshendra/eddb8e665e41849a3f54d009bed82cf8 to your computer and use it in GitHub Desktop.
Save akshendra/eddb8e665e41849a3f54d009bed82cf8 to your computer and use it in GitHub Desktop.
Extended error
/**
* @class QError
*/
class QError extends Error {
/**
* @param {string} message
* @param {string} [type=error]
* @param {Object} [cause=null] - extra data for debugging
*/
constructor(message, type = 'error', cause = null) {
super(message);
this.name = 'QError';
this.type = type;
this.cause = cause;
if (typeof Error.captureStackTrace === 'function') {
Error.captureStackTrace(this, this.constructor);
} else {
this.stack = (new Error(message)).stack;
}
}
}
module.exports = QError;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment