Skip to content

Instantly share code, notes, and snippets.

@saurabhpati
Created June 30, 2018 09:20
Show Gist options
  • Save saurabhpati/415050b92f3b5b6e3591332c33462f3f to your computer and use it in GitHub Desktop.
Save saurabhpati/415050b92f3b5b6e3591332c33462f3f to your computer and use it in GitHub Desktop.
Implementing a custom $exceptionHandler using factory function in angularjs
angular
.module('demoModule')
.factory('$exceptionHandler', ['$injector', function ($injector) {
return function (...args) {
var http = $injector.get('$http');
var info = {
exception: args[0],
cause: args[1]
};
console.log('Exception caught by $exceptionHandler', ...args);
http({ method: 'POST', data: info, url: 'http://localhost:49837/api/logs/exceptions' })
.then(response => console.log('exception info submitted to server...'))
.catch(reason => console.error('unable to send exception info to server due to...', reason));
}
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment