Skip to content

Instantly share code, notes, and snippets.

@bbrown
Created April 21, 2015 19:59
Show Gist options
  • Save bbrown/f241f8c479e7e81f1702 to your computer and use it in GitHub Desktop.
Save bbrown/f241f8c479e7e81f1702 to your computer and use it in GitHub Desktop.
Angular decorator to handle unhandled exceptions, if necessary.
// 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