Skip to content

Instantly share code, notes, and snippets.

@newtriks
Created July 8, 2014 11:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save newtriks/42b462654f3a4459a5ec to your computer and use it in GitHub Desktop.
Save newtriks/42b462654f3a4459a5ec to your computer and use it in GitHub Desktop.
Example using provider and ng-mixin
angular.module('app', []).config(require('./common/exceptions’));
'use strict';
var mix = require('ng-mixin');
module.exports = mix({
$inject: ['$provide'],
init: function ($provide) {
$provide.decorator('$exceptionHandler', ['$delegate', '$injector',
function ($delegate, $injector) {
return function (exception, cause) {
if (exception.name === 'Exception') {
$injector.invoke(['$rootScope',
function ($rootScope) {
$rootScope.$broadcast('error', exception.message);
}
]);
} else {
$delegate(exception, cause);
}
};
}
]);
}
});
'use strict';
var mix = require('ng-mixin');
var ExceptionHandler = require('./exception-handler');
module.exports = function ($provide) {
return new ExceptionHandler($provide);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment