AngularJs Exception Handler going in infinite loop -
AngularJs Exception Handler going in infinite loop -
i'm trying create angularjs app server level logging exceptions.
my code:
exceptionhandler.js
app.config(function($provide){ $provide.decorator("$exceptionhandler", function($injector,$log, exceptionmodel, exceptionservice){ homecoming function(exception, cause){ //$log.error.apply( $log, arguments ); var exceptionmodel = new exceptionmodel(); exceptionmodel.exception = "exception"; exceptionmodel.cause = "cause"; exceptionmodel.stacktrace = "stacktrace"; exceptionservice.logexception(exceptionmodel). catch(function(){ // nothing}); }; }); });
exceptionservice.js
app.service("exceptionservice", function ($injector) { var _logexception = function (exception) { var $httpresource = $injector.get("$resource"); homecoming $httpresource(url, {}).post(exception).$promise; } this.logexception = _logexception });
whenever above exception logging api not available(404 error), angularjs exceptionhandling goes in infinite loop. there i'm missing?
is there way can suppress errors in angularjs i.e., @ $exceptionhandler not raise exception if goes wrong in sending error server api or if error handled @ layer.
first, should not need inject $injector service, should able inject $resource. recommend using mill exceptionservice instead, have work.
if running infinite loop, returned method must throwing error during execution, in turn calls exception handler, throws error, , on.
if goes wrong during post, not result in thrown error. problem may in constructor of exceptionmodel.
i notice variable url in exceptionservice not defined anywhere, may throwing error, unless portion of code omitted clarity.
also, post method not available $resource, $http. example, appears should switch $resource $http, not using resource:
app.service("exceptionservice", function ($http) { var _logexception = function (exception) { homecoming $http.post(url, exception); } this.logexception = _logexception; });
angularjs exception-handling
Comments
Post a Comment