Incorporating a custom error into Angular is a task I am looking to achieve. My goal is to create a personalized error that can be easily thrown in any part of Angular, whether it be a service, controller, or elsewhere. I don't want to have to go through the hassle of 'dependency injecting' the CustomError every time.
function CustomError(message) {
Error.captureStackTrace(this);
this.message = message;
this.name = "SomeCustomError";
}
CustomError.prototype = Object.create(Error.prototype);
One approach I am considering is simply throwing the custom error like this:
throw CustomError('some message');
Alternatively, I could also do it this way:
throw {name : "CustomError", message : "some message"};
What are your thoughts on this?