Last active
May 2, 2018 10:34
-
-
Save DimitarNestorov/a05757c2519f2d8374b2b6480a708d14 to your computer and use it in GitHub Desktop.
@sentry/electron support for AngularJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sentry = require('./sentry.js').moduleName; | |
angular.module('app', ['your', 'dependencies', sentry]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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