I need to assigne an code/id to my custom error:
This is when I create the error:
var err=new Error(\'Numero massimo di cambi di username raggiunto\'
Define
function MyError(code, message) {
this.code = code;
this.message = message;
Error.captureStackTrace(this, MyError);
}
util.inherits(MyError, Error);
MyError.prototype.name = 'MyError';
Raise
throw new MyError(777, 'Smth wrong');
Catch
if (err instanceof MyError) {
console.log(err.code, err.message);
}