0

We are collecting error events using $exceptionHandler, inside the $exceptionHandler callback callback we store exception infomration in a global array.

But when we iterate the exception object manually it shows data, in the debugger it shows data also but when we use JSON.stringify(exception) it returns just {} braces.

What may be the problem ?

My code inside the $exceptionHandler callback :

angular.module('myApp').factory('$exceptionHandler', ['$log', '$injector', function ($log, $injector) {
    var $rootScope;

    return function myExceptionHandler(exception, cause) {
        debugger
        $rootScope = $rootScope || $injector.get('$rootScope');
        var TAG = 'myExceptionHandlerTAG';

        var expJson = JSON.stringify(exception);
        var eve = {
                event : "error",
                params : { user_id : user_id,
                    role : role,
                    time : new Date().getTime(),
                    code_name: navigator.appCodeName,
                    name: navigator.appName ,
                    version: navigator.appVersion ,
                    cookie: navigator.cookieEnabled,
                    language: navigator.language,
                    on_line: navigator.onLine,
                    platform: navigator.platform,
                    user_agent: navigator.userAgent,
                    exception: expJson,
                    cause: cause },             
                source : "web_app" 
            };
        $rootScope.events_json.push(eve);
        $log.error(eve);
    };
}]);

Update:

Contents of exception object in the debugger:

enter image description here

Contents of expJson object in the debugger:

enter image description here

Also, I am not modifying the exception object in the code anywhere except assigning to other variables.

KaraKaplanKhan
  • 734
  • 1
  • 14
  • 31
Prashant
  • 4,474
  • 8
  • 34
  • 82
  • maybe exception properties are not enumerable, so they don't show up in `JSON.stringify` – Francesco Dec 14 '18 at 07:35
  • likely the `exception` object is initially empty and then modified after it's been passed into the function. when you see data in it while using the debugger, what does `JSON.stringify(exception)` show in the console? – ic3b3rg Dec 14 '18 at 07:38
  • 1
    if you want to serialize not enumerable properties you could try something like `JSON.stringify(exception, Object.getOwnPropertyNames(exception))` [stringify doc](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Parameters) – Francesco Dec 14 '18 at 07:44
  • @Francesco Thanks, Your suggestion worked now I am able to see the stringified version of exception, plz post that as an answer I will accept it :) – Prashant Dec 14 '18 at 07:47

0 Answers0