angular.js 865 B

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * Angular.js plugin
  3. *
  4. * Provides an $exceptionHandler for Angular.js
  5. */
  6. ;(function(Raven, angular) {
  7. 'use strict';
  8. // quit if angular isn't on the page
  9. if (!angular) {
  10. return;
  11. }
  12. function ngRavenProvider($provide) {
  13. $provide.decorator('$exceptionHandler', [
  14. 'RavenConfig', '$delegate',
  15. ngRavenExceptionHandler
  16. ]);
  17. }
  18. function ngRavenExceptionHandler(RavenConfig, $delegate) {
  19. if (!RavenConfig)
  20. throw new Error('RavenConfig must be set before using this');
  21. Raven.config(RavenConfig.dsn, RavenConfig.config).install();
  22. return function angularExceptionHandler(ex, cause) {
  23. $delegate(ex, cause);
  24. Raven.captureException(ex, {extra: {cause: cause}});
  25. };
  26. }
  27. angular.module('ngRaven', [])
  28. .config(['$provide', ngRavenProvider])
  29. .value('Raven', Raven);
  30. })(window.Raven, window.angular);