Created
June 30, 2018 09:20
-
-
Save saurabhpati/415050b92f3b5b6e3591332c33462f3f to your computer and use it in GitHub Desktop.
Implementing a custom $exceptionHandler using factory function in angularjs
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('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