-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathangular-raven.js
More file actions
197 lines (173 loc) · 5.76 KB
/
angular-raven.js
File metadata and controls
197 lines (173 loc) · 5.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
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
(function(global, angular, undefined) {
'use strict';
var _development = null;
function $RavenProvider() {
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) {
if (!_development) {
$window.Raven.captureException(exception, cause);
} else {
$log.error('Raven: Exception ', exception, cause);
}
},
captureMessage: function captureMessage(message, data) {
if (!_development) {
$window.Raven.captureMessage(message, data);
} else {
$log.error('Raven: Message ', 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();
}
},
setExtraContext: function setExtraContext(data) {
if (_development) {
$log.info('Raven: Extra Context ', data);
} else {
$window.Raven.setExtraContext(data);
}
},
setRelease: function setRelease(data) {
if (_development) {
$log.info('Raven: Release Context ', data);
} else {
$window.Raven.setRelease(data);
}
},
isSetup: function isSetup() {
return $window.Raven.isSetup();
},
setDataCallback: function setDataCallback(callback) {
return $window.Raven.setDataCallback(callback);
},
setShouldSendCallback: function setShouldSendCallback(callback) {
return $window.Raven.setShouldSendCallback(callback);
},
setTagsContext: function setTagsContext(data) {
if (_development) {
$log.info('Raven: Tags Context ', data);
} else {
$window.Raven.setTagsContext(data);
}
},
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
function $ExceptionHandlerProvider($provide) {
$provide.decorator('$exceptionHandler', [
'$delegate', '$raven', '$injector',
$ExceptionHandlerDecorator
]);
}
function $ExceptionHandlerDecorator($delegate, $raven, $injector) {
// If we try to include a $location object, we will get:
// "Circular dependency found: $location <- $exceptionHandler <- $rootScope"
// Therefore, we inject it.
var $location;
function $ExceptionHandler(exception, cause) {
$location = $location || $injector.get('$location');
var exceptionData = {
culprit: $location.absUrl(),
extra: {
exception: exception,
cause: cause
}
};
if (exception instanceof Error) {
$raven.captureException(exception, exceptionData);
} else {
var message = '';
if (angular.isString(exception.message)) {
message = exception.message;
} else {
message = angular.isString(exception) ? exception : exception.statusText || '';
}
$raven.captureMessage(message, exceptionData);
}
$delegate(exception, cause);
}
return $ExceptionHandler;
}
angular.module('ngRaven', [])
.provider('$raven', $RavenProvider)
.provider('Raven', $RavenProvider)
.config(['$provide', $ExceptionHandlerProvider]);
angular.module('angular-raven', ['ngRaven']);
}(this, angular));