Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
@sentry/electron support for AngularJS
const sentry = require('./sentry.js').moduleName;
angular.module('app', ['your', 'dependencies', sentry]);
const { init } = require('@sentry/electron');
// See https://github.com/angular/angular.js/blob/v1.4.7/src/minErr.js
const angularPattern = /^\[((?:[$a-zA-Z0-9]+:)?(?:[$a-zA-Z0-9]+))\] (.*?)\n?(\S+)$/;
function beforeSend(data){
// We only care about mutating an exception
let exception = data.exception;
if(exception){
exception = exception[0];
const matches = angularPattern.exec(exception.value);
if(matches){
// This type now becomes something like: $rootScope:inprog
exception.type = matches[1];
exception.value = matches[2];
data.message = `${exception.type}: ${exception.value}`;
// auto set a new tag specifically for the angular error url
data.extra.angularDocs = matches[3].substr(0, 250);
}
}
return data;
}
init({
dsn: '**URL**',
beforeSend
});
/* eslint-env browser */
const { init, captureException, setExtraContext } = require('@sentry/electron');
const angular = require('angular');
const moduleName = 'sentry';
ExceptionHandlerProvider.$inject = ['$provide'];
function ExceptionHandlerProvider($provide){
$provide.decorator('$exceptionHandler', exceptionHandler);
}
exceptionHandler.$inject = ['$delegate'];
function exceptionHandler($delegate){
return function(ex, cause){
setExtraContext({cause});
captureException(ex);
setTimeout(() => {
setExtraContext({cause: null});
});
$delegate(ex, cause);
};
}
angular
.module(moduleName, [])
.config(ExceptionHandlerProvider);
const dsn = '**URL**';
init({
dsn
});
exports.moduleName = moduleName;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment