Using AngularJs v1.5.7, I'm having quite some trouble trying to log the exception.
The issue seem to be with the type of the exception.
This object is somehow not a normal object with properties.
Here is a code sample with what I have attempted so far and the result for each attempts.
MyApp.config(['$provide', function ($provide)
{
$provide.decorator('$exceptionHandler', ['$delegate', 'logsService', function ($delegate, logsService)
{
return function (exception, cause)
{
$delegate(exception, cause);
try
{
//Attempt #1 : throw because exception isn't an object.
logsService.addLog(exception);
//Attempt #2 : Log the hardcoded object with both properties
logsService.addLog({a:'Some test', b:'Ok'});
//Attempt #3 : log an empty object because exception has no property
var log = {};
for (var property in exception)
{
if (object.hasOwnProperty(property))
{
log[property] = exception[property];
}
}
logsService.addLog(log);
//Attempt #4 : Log the message, but doesn't log all possible properties that exception could have.
logsService.addLog({ message: exception.message});
}
catch (ignore) { }
};
}]);
}]);
N.B : I can't change the logsService
.
So far, I didn't find anything about this on google.
Why does exception
has no properties and how to work around this limitation?
Edit :
I think I've pinpoint a little more the issue. The exception object is probably not clean and have functions or others things that can't be cloned. This give the following error in the log service.
DataCloneError: Failed to execute 'put' on 'IDBObjectStore'`
Error and Function objects cannot be duplicated by the structured clone algorithm; attempting to do so will throw a DATA_CLONE_ERR exception.
//Attempt #5 : log an empty object because exception has no property.
var cleanedException = JSON.parse(angular.toJson(exception));
logsService.addLog(cleanedException);
Is is what the exception show when inspecting it in the watch.