Created
April 21, 2015 19:59
-
-
Save bbrown/f241f8c479e7e81f1702 to your computer and use it in GitHub Desktop.
Angular decorator to handle unhandled exceptions, if necessary.
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
// All unhandled exceptions in an AngularJS application are passed to a service $exceptionHandler, | |
// which logs the error message in the browser's console. In large business applications, you may want | |
// to log the error details on the server by calling an API. This can be done by decorating the $exceptionHandler service. | |
// #49 - http://www.dotnetcurry.com/showarticle.aspx?ID=1115 | |
app.config(function($provide) | |
{ | |
$provide.decorator('$exceptionHandler', ['$log', '$http', '$delegate', function ($log, $http, $delegate) | |
{ | |
return function (exception, cause) | |
{ | |
$log.debug('Modified exception handler'); | |
$http.post('/api/clientExceptionLogger', exception); | |
$delegate(exception, cause); | |
}; | |
} | |
]); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment