javascript - How to globally access/throw a custom error in angular? -
i create own custom error, this:
function customerror(message) { error.capturestacktrace(this); this.message = message; this.name = "somecustomerror"; } customerror.prototype = object.create(error.prototype);
how should integrate custom errors in angular? able throw same custom error anywhere in angular, no matter if in service, controller, or similar. wouldn't want 'dependency inject' customerror each time.
throw customerror('some message');
or, if thinking about, simply:
throw {name : "customerror", message : "some message"};
any thoughts?
in app.js - bootstrap file, have that:
angular.module('myapp') .run(['$window', function($window) { function customerror(message) { error.capturestacktrace(this); this.message = message; this.name = "somecustomerror"; } customerror.prototype = object.create(error.prototype); $window.customerror = customerror; // here on, can throw anywhere: // throw new customerror("d'oh!"); } ]);
Comments
Post a Comment