Skip to content

Commit 768fdca

Browse files
committed
Merge pull request #407 from getsentry/angular-eror
Handle a native angular minErr by deconstructing it
2 parents 26b0db8 + fda2aa0 commit 768fdca

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

plugins/angular.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,39 @@ function ExceptionHandlerProvider($provide) {
2424
}
2525

2626
function exceptionHandler(Raven, $delegate) {
27-
return function (ex, cause) {
27+
return function (ex, cause) {
2828
Raven.captureException(ex, {
2929
extra: { cause: cause }
3030
});
3131
$delegate(ex, cause);
3232
};
3333
}
3434

35+
// See https://github.com/angular/angular.js/blob/v1.4.7/src/minErr.js
36+
var angularPattern = /^\[((?:[$a-zA-Z0-9]+:)?(?:[$a-zA-Z0-9]+))\] (.+?)\n(\S+)$/;
37+
3538
Raven.addPlugin(function () {
3639
angular.module('ngRaven', [])
3740
.provider('Raven', RavenProvider)
3841
.config(['$provide', ExceptionHandlerProvider]);
3942
});
4043

44+
Raven.setDataCallback(function(data) {
45+
// We only care about mutating an exception
46+
var exception = data.exception;
47+
if (exception) {
48+
exception = exception.values[0];
49+
var matches = angularPattern.exec(exception.value);
50+
51+
if (matches) {
52+
// This type now becomes something like: $rootScope:inprog
53+
exception.type = matches[1];
54+
exception.value = matches[2];
55+
data.message = exception.type + ': ' + exception.value;
56+
// auto set a new tag specifically for the angular error url
57+
data.extra.angularDocs = matches[3].substr(0, 250);
58+
}
59+
}
60+
});
61+
4162
}(typeof window !== 'undefined' ? window : this));

0 commit comments

Comments
 (0)