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

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -