forked from exceptionless/Exceptionless.JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular.js
107 lines (107 loc) · 5.45 KB
/
angular.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
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var angular = require("angular");
angular.module('exceptionless', [])
.constant('$ExceptionlessClient', exceptionless.ExceptionlessClient.default)
.factory('exceptionlessHttpInterceptor', ['$q', '$ExceptionlessClient', function ($q, $ExceptionlessClient) {
return {
responseError: function responseError(rejection) {
if (rejection.status === 404) {
$ExceptionlessClient.submitNotFound(rejection.config.url);
}
else if (rejection.status !== 401) {
var message = "[" + rejection.status + "] " + (rejection.data && rejection.data.Message ? rejection.data.Message : rejection.config.url);
$ExceptionlessClient.createUnhandledException(new Error(message), 'errorHttpInterceptor')
.setManualStackingInfo({ Status: rejection.status, ExceptionType: 'Error', Path: rejection.config.method + ' ' + rejection.config.url })
.setSource(rejection.config.url)
.setProperty('request', rejection.config)
.submit();
}
return $q.reject(rejection);
}
};
}])
.config(['$httpProvider', '$provide', '$ExceptionlessClient', function ($httpProvider, $provide, $ExceptionlessClient) {
$httpProvider.interceptors.push('exceptionlessHttpInterceptor');
$provide.decorator('$exceptionHandler', ['$delegate', function ($delegate) {
return function (exception, cause) {
$delegate(exception, cause);
$ExceptionlessClient.createUnhandledException(exception, '$exceptionHandler').setMessage(cause).submit();
};
}]);
$provide.decorator('$log', ['$delegate', function ($delegate) {
function decorateRegularCall(property, logLevel) {
var previousFn = $delegate[property];
return $delegate[property] = function () {
if (angular.mock) {
$delegate[property].logs = [];
}
previousFn.apply(null, arguments);
if (arguments[0] && arguments[0].length > 0) {
$ExceptionlessClient.submitLog(null, arguments[0], logLevel);
}
};
}
$delegate.log = decorateRegularCall('log', 'Trace');
$delegate.info = decorateRegularCall('info', 'Info');
$delegate.warn = decorateRegularCall('warn', 'Warn');
$delegate.debug = decorateRegularCall('debug', 'Debug');
$delegate.error = decorateRegularCall('error', 'Error');
return $delegate;
}]);
}])
.run(['$rootScope', '$ExceptionlessClient', function ($rootScope, $ExceptionlessClient) {
$rootScope.$on('$routeChangeSuccess', function (event, next, current) {
if (!current) {
return;
}
$ExceptionlessClient.createFeatureUsage(current.name)
.setProperty('next', next)
.setProperty('current', current)
.submit();
});
$rootScope.$on('$routeChangeError', function (event, current, previous, rejection) {
$ExceptionlessClient.createUnhandledException(new Error(rejection), '$routeChangeError')
.setProperty('current', current)
.setProperty('previous', previous)
.submit();
});
$rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState, fromParams) {
if (!toState || toState.name === 'otherwise') {
return;
}
$ExceptionlessClient.createFeatureUsage(toState.controller || toState.name)
.setProperty('toState', toState)
.setProperty('toParams', toParams)
.setProperty('fromState', fromState)
.setProperty('fromParams', fromParams)
.submit();
});
$rootScope.$on('$stateNotFound', function (event, unfoundState, fromState, fromParams) {
if (!unfoundState) {
return;
}
$ExceptionlessClient.createNotFound(unfoundState.to)
.setProperty('unfoundState', unfoundState)
.setProperty('fromState', fromState)
.setProperty('fromParams', fromParams)
.submit();
});
var stateChangeError = '$stateChangeError';
$rootScope.$on(stateChangeError, function (event, toState, toParams, fromState, fromParams, error) {
if (!error) {
return;
}
var builder = error && error.status === 404 ? $ExceptionlessClient.createNotFound(error.config.url) : $ExceptionlessClient.createUnhandledException(error, stateChangeError);
builder.setSource(stateChangeError)
.setMessage(error && error.statusText)
.setProperty('toState', toState)
.setProperty('toParams', toParams)
.setProperty('fromState', fromState)
.setProperty('fromParams', fromParams)
.submit();
});
$rootScope.$on('$destroy', function () {
$ExceptionlessClient.config.queue.process();
});
}]);