Ragun is undefined when using in SPA. angularjs
ecaldwell
Posted on
Apr 08 2016
I am getting that raygun in undefined, sometimes within running my Single Page Application. Sometimes I get it upon just refreshing the page . angular.js:9778 ReferenceError Raygun is not defined (caused by "undefined")
angular.module('exceptionOverride', []).factory('$exceptionHandler',['$injector', function ($injector) { return function (exception, cause) { var logservice = $injector.get('loggingService'); var $log = $injector.get('$log'); var stacktraceService = $injector.get('stacktraceService'); var $state = $injector.get('$state'); var raygunService = $injector.get('raygunService'); exception.message += ' (caused by "' + cause + '")'; $log.error(exception.name + ' ' + exception.message); // get the stack trace var stackTrace = stacktraceService.print({ e: exception }); $log.error(stackTrace.join('\n')); // will add new line to each level of the stack logservice.error(exception.message + stackTrace.join('\n')); // Send exception error to Raygun for reporting// Raygun.send(exception, cause); //raygunService.send(exception, cause); // only redirect to general error page if it is not a userexception. if (exception.name !== 'UserException') { if ($state.$current.includes.popup === true) { // a specific error on a specific page is causing an un needed redirect. if (!$state.$current.includes("popup.realEC")) { $state.go('popup.error'); } } else { $state.go('root.error'); } } }; }]); })();
Callum
Posted on
Apr 08 2016
Hi,
Could you confirm details on how you've set up Raygun4JS - for instance, are you using the async Snippet at the bottom of the element, and the config blocks at the bottom of the body? The most likely scenario is this application code in the exceptionOverride callback is being run while Raygun4JS is being download and not yet parsed/executed, in which case the global Raygun object is not yet available.
If it is indeed the above case, we are planning to add a feature to the rg4js() config object to queue and proxy Send calls through to the Raygun object when it becomes available, this is contingent on testing and QA due to the need to maintain backwards compat. and ensure no breaking changes for legacy browsers, but is in the pipeline.
Callum
Posted on
Apr 11 2016
Ticket closed via email
WhittenMike807
Posted on
Apr 28 2016
I'm getting the same error. Was this resolved?
WhittenMike807
Posted on
Apr 28 2016
Still testing, but this is how I resolved it in case anyone else runs into this issue:
angular.module("mapApp").factory("errors", function errorLoggerFactory($window) { return ({ report: report });
function defer(method) {
if ($window.Raygun)
method();
else
setTimeout(function () {
console.log('Raygun not loaded let, trying again...');
defer(method);
}, 50);
}
function report(error, cause) {
defer(function () {
console.log('Raygun is now loaded');
$window.Raygun.send(error, { cause: cause });
});
}
});
Callum
Posted on
Apr 28 2016
That's a good workaround, the work item to implement send() queuing with rg4js which would fix this race condition is still outstanding but we're aiming to get time to address this in an upcoming sprint.
Regards,
Callum Gavin
Raygun Limited