Repository navigation
Expand file tree
/
Copy pathangular.js
More file actions
60 lines (50 loc) · 1.76 KB
/
Copy pathangular.js
File metadata and controls
60 lines (50 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* Angular.js plugin
*
* Provides an $exceptionHandler for Angular.js
*/
'use strict';
// See https://github.com/angular/angular.js/blob/v1.4.7/src/minErr.js
var angularPattern = /^\[((?:[$a-zA-Z0-9]+:)?(?:[$a-zA-Z0-9]+))\] (.+?)\n(\S+)$/;
function angularPlugin(Raven, angular) {
angular = angular || window.angular;
if (!angular) return;
function RavenProvider() {
this.$get = ['$window', function($window) {
return Raven;
}];
}
function ExceptionHandlerProvider($provide) {
$provide.decorator('$exceptionHandler',
['Raven', '$delegate', exceptionHandler]);
}
function exceptionHandler(R, $delegate) {
return function (ex, cause) {
R.captureException(ex, {
extra: { cause: cause }
});
$delegate(ex, cause);
};
}
angular.module('ngRaven', [])
.provider('Raven', RavenProvider)
.config(['$provide', ExceptionHandlerProvider]);
Raven.setDataCallback(function(data, original) {
// We only care about mutating an exception
var exception = data.exception;
if (exception) {
exception = exception.values[0];
var 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);
}
}
original && original(data);
});
}
module.exports = angularPlugin;