From 7387d871ecd8982e189e607b6034076dfcd687ed Mon Sep 17 00:00:00 2001 From: Gediminas Ubartas Date: Thu, 25 Jun 2015 11:38:53 +0300 Subject: [PATCH] Prevent logging same errors --- dist/angular-error-logger.js | 2 +- src/angular-error-logger-service.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/dist/angular-error-logger.js b/dist/angular-error-logger.js index da99b34..6fe34bb 100644 --- a/dist/angular-error-logger.js +++ b/dist/angular-error-logger.js @@ -1 +1 @@ -angular.module("angularErrorLogger",[]),angular.module("angularErrorLogger").factory("exceptionSender",["$injector","$log",function(r,e){"use strict";return{sendException:function(o,n){e.debug("logging error to server side: serviceUrl = "+o),e.debug("logging error to server side...",n);var g=r.get("$http");g.post(o,n).then(function(){e.info("Error logged")},function(r){e.warn("Error logging to server side failed"),e.log(r)})}}}]),angular.module("angularErrorLogger").provider("$exceptionHandler",{$get:["angularErrorLoggerService",function(r){"use strict";return r}]}),angular.module("angularErrorLogger").factory("angularErrorLoggerService",["$log","$window","exceptionSender","ANGULAR_ERROR_LOGGER_CONFIG",function(r,e,o,n){"use strict";function g(g,t){var a=[],i=g?g.toString():"no exception",u=g?g.stack?g.stack.toString():"no stack":"no exception",c={navigatorAppName:navigator.appName,navigatorUserAgent:navigator.userAgent},l=angular.toJson({errorUrl:e.location.href,errorMessage:i,stackTrace:u,cause:t||"no cause",browserInfo:c});-1===a.indexOf(u)?(n&&n.url&&o.sendException(n.url,l),a.push(u)):r.debug("Dublicated error")}function t(e,o){r.debug("errorLogService.log()"),r.error.apply(r,arguments),g(e,o)}return t}]); \ No newline at end of file +angular.module("angularErrorLogger",[]),angular.module("angularErrorLogger").factory("exceptionSender",["$injector","$log",function(r,e){"use strict";return{sendException:function(o,n){e.debug("logging error to server side: serviceUrl = "+o),e.debug("logging error to server side...",n);var g=r.get("$http");g.post(o,n).then(function(){e.info("Error logged")},function(r){e.warn("Error logging to server side failed"),e.log(r)})}}}]),angular.module("angularErrorLogger").provider("$exceptionHandler",{$get:["angularErrorLoggerService",function(r){"use strict";return r}]}),angular.module("angularErrorLogger").factory("angularErrorLoggerService",["$log","$window","exceptionSender","ANGULAR_ERROR_LOGGER_CONFIG",function(r,e,o,n){"use strict";function g(g,t){var i=g?g.toString():"no exception",u=g?g.stack?g.stack.toString():"no stack":"no exception",c={navigatorAppName:navigator.appName,navigatorUserAgent:navigator.userAgent},l=angular.toJson({errorUrl:e.location.href,errorMessage:i,stackTrace:u,cause:t||"no cause",browserInfo:c});-1===a.indexOf(u)?(n&&n.url&&o.sendException(n.url,l),a.push(u)):r.debug("Dublicated error. No logging sent")}function t(e,o){r.debug("errorLogService.log()"),r.error.apply(r,arguments),g(e,o)}var a=[];return t}]); \ No newline at end of file diff --git a/src/angular-error-logger-service.js b/src/angular-error-logger-service.js index 2012843..9ea50fc 100644 --- a/src/angular-error-logger-service.js +++ b/src/angular-error-logger-service.js @@ -2,9 +2,10 @@ angular.module('angularErrorLogger').factory( "angularErrorLoggerService", function ($log, $window, exceptionSender, ANGULAR_ERROR_LOGGER_CONFIG) { 'use strict'; + var loggedExceptions = []; + function logErrorToServerSide(exception, cause) { - var loggedExceptions = [], - errorMessage = exception ? exception.toString() : "no exception", + var errorMessage = exception ? exception.toString() : "no exception", stackTrace = exception ? (exception.stack ? exception.stack.toString() : "no stack") : "no exception", browserInfo = { @@ -25,7 +26,7 @@ angular.module('angularErrorLogger').factory( } loggedExceptions.push(stackTrace); } else { - $log.debug("Dublicated error"); + $log.debug("Dublicated error. No logging sent"); } }