Here I created Custom Error class in Node.js. I created this ErrorClass to send Custom error response of api call.
I want to catch this CustomError
class in Bluebird Catch promises
.
Object.defineProperty(Error.prototype, 'message', {
configurable: true,
enumerable: true
});
Object.defineProperty(Error.prototype, 'stack', {
configurable: true,
enumerable: true
});
Object.defineProperty(Error.prototype, 'toJSON', {
value: function () {
var alt = {};
Object.getOwnPropertyNames(this).forEach(function (key) {
alt[key] = this[key];
}, this);
return alt;
},
configurable: true
});
Object.defineProperty(Error.prototype, 'errCode', {
configurable: true,
enumerable: true
});
function CustomError(errcode, err, message) {
Error.captureStackTrace(this, this.constructor);
this.name = 'CustomError';
this.message = message;
this.errcode = errcode;
this.err = err;
}
CustomError.prototype = Object.create(Error.prototype);
I wanna convert this into node-module but I am not getting how to do that.