Created
July 8, 2014 11:02
-
-
Save newtriks/42b462654f3a4459a5ec to your computer and use it in GitHub Desktop.
Example using provider and ng-mixin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('app', []).config(require('./common/exceptions’)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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); | |
} | |
}; | |
} | |
]); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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