Skip to content

Instantly share code, notes, and snippets.

@xcarpentier
Created December 15, 2014 15:31
Show Gist options
  • Save xcarpentier/21fd5ebac309b91a3306 to your computer and use it in GitHub Desktop.
Save xcarpentier/21fd5ebac309b91a3306 to your computer and use it in GitHub Desktop.
/* recommandé */
angular
.module('blocks.exception')
.config(exceptionConfig);
exceptionConfig.$inject = ['$provide'];
function exceptionConfig($provide) {
$provide.decorator('$exceptionHandler', extendExceptionHandler);
}
extendExceptionHandler.$inject = ['$delegate', 'toastr'];
function extendExceptionHandler($delegate, toastr) {
return function (exception, cause) {
$delegate(exception, cause);
var errorData = {
exception: exception,
cause: cause
};
/**
* Peut ajouter l'erreur dans un service qui les collecte
* ajouter l'erreur au $rootScope, envoyer l'erreur à un serveur,
* ou un log local. Ou lever l'exception. C'est une décision qui vous revient.
* throw exception;
*/
toastr.error(exception.msg, errorData);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment