forked from PatrickJS/angular-raven
-
Notifications
You must be signed in to change notification settings - Fork 0
/
angular-raven.js
132 lines (115 loc) · 3.74 KB
/
angular-raven.js
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
!function(module, angular, undefined) {
'use strict';
module.provider('Raven', function() {
var _development = null;
this.development = function(config) {
_development = config || _development;
return this;
};
this.$get = ['$window', '$log', function($window, $log) {
var service = {
VERSION: ($window.Raven) ? $window.Raven.VERSION : 'development',
TraceKit: ($window.Raven) ? $window.Raven.TraceKit : 'development',
captureException: function captureException(exception, cause) {
$log.error('Raven: Exception ', exception, cause);
if (!_development) {
$window.Raven.captureException(exception, cause);
}
},
captureMessage: function captureMessage(message, data) {
if (_development) {
$log.error('Raven: Message ', message, data);
} else {
$window.Raven.captureMessage(message, data);
}
},
setUser: function setUser(user) {
if (_development) {
$log.info('Raven: User ', user);
} else {
if ($window.Raven.setUser) {
$window.Raven.setUser(user);
} else if ($window.Raven.setUserContext) {
$window.Raven.setUserContext(user);
}
}
},
setUserContext: function setUserContext(user) {
if (_development) {
$log.info('Raven: User ', user);
} else {
if ($window.Raven.setUserContext) {
$window.Raven.setUserContext(user);
} else if ($window.Raven.setUser) {
$window.Raven.setUser(user);
}
}
},
lastException: function lastException() {
if (_development) {
$log.error('Raven: Last Exception');
} else {
$window.Raven.lastException();
}
},
context: function context(options, func, args) {
var RavenService = this;
if (angular.isFunction(options)) {
args = func || [];
func = options;
options = undefined;
}
return RavenService.wrap(options, func).apply(RavenService, args);
},
wrap: function wrap(options, func) {
var RavenService = this;
if (angular.isUndefined(func) && !angular.isFunction(options)) {
return options;
}
if (angular.isFunction(options)) {
func = options;
options = undefined;
}
if (!angular.isFunction(func)) {
return func;
}
if (func.__raven__) {
return func;
}
function wrapped() {
var args = [], i = arguments.length;
while(i--) args[i] = RavenService.wrap(options, arguments[i]);
try {
return func.apply(this, args);
} catch(e) {
RavenService.captureException(e, options);
}
}
for (var property in func) {
if (func.hasOwnProperty(property)) {
wrapped[property] = func[property];
}
}
wrapped.__raven__ = true;
return wrapped;
}
};
return service;
}]; // end $get
}); // end provider
module.factory('$exceptionHandler', ['Raven', function(Raven) {
return function(exception, cause) {
if (exception instanceof Error) {
Raven.captureException(exception, cause);
} else {
Raven.captureMessage(exception, {
exception: exception,
cause: cause
});
}
};
}]);
module.factory('$raven', ['Raven', function(Raven) {
return Raven;
}]);
}(angular.module('ngRaven', []), angular);