Skip to content

include angular-raven module for plugins #156

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions plugins/angular.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
;(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) {
if (_development) {
$log.error('Raven: Exception ', exception, cause);
} else {
$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.error('Raven: User ', user);
} else {
$window.Raven.setUser(user);
}
},
lastException: function lastException() {
if (_development) {
$log.error('Raven: Last Exception');
} else {
$window.Raven.lastException();
}
},
context: function(options, func, args) {
var RavenService = this;

if (angular.isFunction(options)) {
args = func || [];
func = options;
options = undefined;
}

return RavenService.wrap(options, func).apply(this, args);
},
wrap: function(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) {
Raven.captureException(exception, cause);
};
}]);

}(angular.module('ngRaven', []), angular));