Skip to content
This repository was archived by the owner on Mar 4, 2025. It is now read-only.

Commit 180956d

Browse files
author
Nick Litwin
committed
Log errors to new relic
1 parent 70175c9 commit 180956d

37 files changed

+397
-289
lines changed

app/account/login/login.controller.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import angular from 'angular'
55

66
angular.module('tc.account').controller('LoginController', LoginController)
77

8-
LoginController.$inject = ['$log', '$state', '$stateParams', '$location', '$scope', 'TcAuthService', 'UserService', 'Helpers', 'CONSTANTS']
8+
LoginController.$inject = ['$log', 'logger', '$state', '$stateParams', '$location', '$scope', 'TcAuthService', 'UserService', 'Helpers', 'CONSTANTS']
99

10-
function LoginController($log, $state, $stateParams, $location, $scope, TcAuthService, UserService, Helpers, CONSTANTS) {
10+
function LoginController($log, logger, $state, $stateParams, $location, $scope, TcAuthService, UserService, Helpers, CONSTANTS) {
1111
var vm = this
12-
$log = $log.getInstance('LoginController')
1312
vm.$stateParams = $stateParams
1413
vm.passwordReset = false
1514
vm.loginErrors = {
@@ -84,9 +83,9 @@ import angular from 'angular'
8483
Helpers.setupLoginEventMetrics(usernameOrEmail)
8584
return Helpers.redirectPostLogin($stateParams.next)
8685

87-
}).catch(function(resp) {
88-
$log.warn(resp)
89-
switch (resp.status) {
86+
}).catch(function(err) {
87+
$log.warn(err)
88+
switch (err.status) {
9089
case 'ACCOUNT_INACTIVE':
9190
$state.go('registeredSuccessfully')
9291
// user should already be redirected
@@ -95,6 +94,7 @@ import angular from 'angular'
9594
default:
9695
vm.loginErrors.WRONG_PASSWORD = true
9796
vm.password = ''
97+
logger.error('Error logging in: ', err)
9898
}
9999
})
100100
}
@@ -114,16 +114,16 @@ import angular from 'angular'
114114
$log.debug('logged in')
115115
return Helpers.redirectPostLogin($stateParams.next)
116116
})
117-
.catch(function(resp) {
117+
.catch(function(err) {
118118
/*eslint no-fallthrough:0*/
119-
switch (resp.status) {
119+
switch (err.status) {
120120
case 'ACCOUNT_INACTIVE':
121121
window.location.href = 'https://www.' + CONSTANTS.domain + '/account-inactive/'
122122
case 'USER_NOT_REGISTERED':
123123
default:
124124
vm.socialLoginError = 401
125125
vm.loginErrors.SOCIAL_LOGIN_ERROR = true
126-
break
126+
logger.error('Error logging in with social account', err)
127127
}
128128
})
129129
}

app/account/logout/logout.controller.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@ import angular from 'angular'
88
LogoutController.$inject = ['$log', 'TcAuthService', '$window', 'CONSTANTS']
99

1010
function LogoutController($log, TcAuthService, $window, CONSTANTS) {
11-
$log = $log.getInstance('LogoutController')
12-
1311
TcAuthService.logout()
1412
.then(function() {
1513
$log.debug('successfully logged out.')
1614
// redirect to home
1715
$window.location.href = CONSTANTS.MAIN_URL
1816
})
19-
2017
}
2118
})()

app/account/register/register.controller.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import _ from 'lodash'
66

77
angular.module('tc.account').controller('RegisterController', RegisterController)
88

9-
RegisterController.$inject = ['$log', 'CONSTANTS', '$state', '$stateParams', 'TcAuthService', 'UserService', 'ISO3166', 'Helpers']
9+
RegisterController.$inject = ['$log', 'logger', 'CONSTANTS', '$state', '$stateParams', 'TcAuthService', 'UserService', 'ISO3166', 'Helpers']
1010

11-
function RegisterController($log, CONSTANTS, $state, $stateParams, TcAuthService, UserService, ISO3166, Helpers) {
11+
function RegisterController($log, logger, CONSTANTS, $state, $stateParams, TcAuthService, UserService, ISO3166, Helpers) {
1212
$log = $log.getInstance('RegisterController')
1313
$log.debug('-init')
1414
var vm = this
@@ -96,7 +96,8 @@ import _ from 'lodash'
9696
})
9797
.catch(function(err) {
9898
vm.registering = false
99-
$log.error('Error in registering new user: ', err)
99+
100+
logger.error('Error in registering new user', err)
100101
})
101102
}
102103

@@ -130,17 +131,22 @@ import _ from 'lodash'
130131
vm.isSocialRegistration = false
131132
}
132133
})
133-
.catch(function(result) {
134-
switch (result.status) {
135-
case 'SOCIAL_PROFILE_ALREADY_EXISTS':
136-
vm.errMsg = 'An account with that profile already exists. Please login to access your account.'
137-
break
138-
default:
139-
vm.errMsg = 'Whoops! Something went wrong. Please try again later.'
140-
break
141-
}
142-
vm.isSocialRegistration = false
143-
})
134+
.catch(function(err) {
135+
switch (err.status) {
136+
case 'SOCIAL_PROFILE_ALREADY_EXISTS':
137+
vm.errMsg = 'An account with that profile already exists. Please login to access your account.'
138+
139+
logger.error('Error registering user with social account', err)
140+
141+
break
142+
143+
default:
144+
vm.errMsg = 'Whoops! Something went wrong. Please try again later.'
145+
146+
logger.error('Error registering user with social account', err)
147+
}
148+
vm.isSocialRegistration = false
149+
})
144150
}
145151

146152
vm.$stateParams = $stateParams

app/blocks/logger/logger.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,18 @@ import angular from 'angular'
2525
/////////////////////
2626

2727
function error(message, data, title) {
28-
$log.error('Error: ' + message, data)
28+
debugger
29+
if (data) {
30+
message = `${message} ${JSON.stringify(data)}`
31+
}
32+
33+
$log.error(message)
34+
35+
if (window.NREUM) {
36+
var err = new Error(message)
37+
38+
window.NREUM.noticeError(err)
39+
}
2940
}
3041

3142
function info(message, data, title) {

app/directives/external-account/external-account.directive.js

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import _ from 'lodash'
2424
linkedAccounts: '=',
2525
readOnly: '='
2626
},
27-
controller: ['$log', '$scope', 'ExternalAccountService', 'toaster',
28-
function($log, $scope, ExternalAccountService, toaster) {
27+
controller: ['$log', 'logger', '$scope', 'ExternalAccountService', 'toaster',
28+
function($log, logger, $scope, ExternalAccountService, toaster) {
2929

3030
$log = $log.getInstance('ExtAccountDirectiveCtrl')
3131

@@ -80,9 +80,10 @@ import _ from 'lodash'
8080
)
8181
)
8282
})
83-
.catch(function(resp) {
84-
if (resp.status === 'SOCIAL_PROFILE_ALREADY_EXISTS') {
83+
.catch(function(err) {
84+
if (err.status === 'SOCIAL_PROFILE_ALREADY_EXISTS') {
8585
$log.info('Social profile already linked to another account')
86+
8687
toaster.pop('error', 'Whoops!',
8788
String.supplant(
8889
'This {provider} account is linked to another account. \
@@ -91,7 +92,8 @@ import _ from 'lodash'
9192
)
9293
)
9394
} else {
94-
$log.error('Fatal Error: _link: ' + resp.msg)
95+
logger.error('Fatal Error: _link: ', err.msg)
96+
9597
toaster.pop('error', 'Whoops!', 'Sorry, we are unable to add your account right now. Please try again later. If the problem persists, please contact <a href=\"mailTo:[email protected]\">[email protected]</a>.')
9698
}
9799
})
@@ -115,13 +117,16 @@ import _ from 'lodash'
115117
)
116118
)
117119
})
118-
.catch(function(resp) {
119-
var msg = resp.msg
120-
if (resp.status === 'SOCIAL_PROFILE_NOT_EXIST') {
120+
.catch(function(err) {
121+
var msg = err.msg
122+
123+
if (err.status === 'SOCIAL_PROFILE_NOT_EXIST') {
121124
$log.info('Social profile not linked to account')
125+
122126
msg = '{provider} account is not linked to your account. If you think this is an error please contact <a href=\"mailTo:[email protected]\">[email protected]</a>.'
123127
} else {
124-
$log.error('Fatal error: _unlink: ' + msg)
128+
logger.error('Fatal error: _unlink', msg)
129+
125130
msg = 'Sorry! We are unable to unlink your {provider} account. If problem persists, please contact <a href=\"mailTo:[email protected]\">[email protected]</a>'
126131
}
127132
toaster.pop('error', 'Whoops!', String.supplant(msg, {provider: provider.displayName }))

app/directives/external-account/external-link-deletion.controller.js

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,56 @@ import angular from 'angular'
22
import _ from 'lodash'
33

44
(function () {
5-
65
angular.module('tcUIComponents')
76
.controller('ExternalLinkDeletionController', ExternalLinkDeletionController)
87

9-
ExternalLinkDeletionController.$inject = ['ExternalWebLinksService', '$q', '$log', 'toaster', 'ngDialog', 'userHandle', 'account', 'linkedAccountsData']
8+
ExternalLinkDeletionController.$inject = ['ExternalWebLinksService', '$q', '$log', 'logger', 'toaster', 'ngDialog', 'userHandle', 'account', 'linkedAccountsData']
109

11-
function ExternalLinkDeletionController(ExternalWebLinksService, $q, $log, toaster, ngDialog, userHandle, account, linkedAccountsData) {
10+
function ExternalLinkDeletionController(ExternalWebLinksService, $q, $log, logger, toaster, ngDialog, userHandle, account, linkedAccountsData) {
1211
var vm = this
1312
vm.account = account
1413
$log = $log.getInstance('ExternalLinkDeletionController')
1514

1615
vm.deleteAccount = function() {
1716
$log.debug('Deleting Account...')
17+
1818
if (account && account.deletingAccount) {
1919
$log.debug('Another deletion is already in progress.')
2020
return
2121
}
22+
2223
if (account && account.provider === 'weblink') {
2324
account.deletingAccount = true
2425
$log.debug('Deleting weblink...')
25-
return ExternalWebLinksService.removeLink(userHandle, account.key).then(function(data) {
26-
account.deletingAccount = false
27-
$log.debug('Web link removed: ' + JSON.stringify(data))
28-
var toRemove = _.findIndex(linkedAccountsData, function(la) {
29-
return la.provider === 'weblink' && la.key === account.key
26+
27+
return ExternalWebLinksService.removeLink(userHandle, account.key)
28+
.then(function(data) {
29+
account.deletingAccount = false
30+
$log.debug('Web link removed: ' + JSON.stringify(data))
31+
var toRemove = _.findIndex(linkedAccountsData, function(la) {
32+
return la.provider === 'weblink' && la.key === account.key
33+
})
34+
if (toRemove > -1) {
35+
// remove from the linkedAccountsData array
36+
linkedAccountsData.splice(toRemove, 1)
37+
}
38+
toaster.pop('success', 'Success', 'Your link has been removed.')
39+
})
40+
.catch(function(err) {
41+
var msg = err.msg
42+
if (err.status === 'WEBLINK_NOT_EXIST') {
43+
$log.info('Weblink does not exist')
44+
45+
msg = 'Weblink is not linked to your account. If you think this is an error please contact <a href=\"mailTo:[email protected]\">[email protected]</a>.'
46+
} else {
47+
logger.error('Fatal error: _unlink', msg)
48+
49+
msg = 'Sorry! We are unable to remove your weblink. If problem persists, please contact <a href=\"mailTo:[email protected]\">[email protected]</a>'
50+
}
51+
52+
account.deletingAccount = false
53+
toaster.pop('error', 'Whoops!', msg)
3054
})
31-
if (toRemove > -1) {
32-
// remove from the linkedAccountsData array
33-
linkedAccountsData.splice(toRemove, 1)
34-
}
35-
toaster.pop('success', 'Success', 'Your link has been removed.')
36-
})
37-
.catch(function(resp) {
38-
var msg = resp.msg
39-
if (resp.status === 'WEBLINK_NOT_EXIST') {
40-
$log.info('Weblink does not exist')
41-
msg = 'Weblink is not linked to your account. If you think this is an error please contact <a href=\"mailTo:[email protected]\">[email protected]</a>.'
42-
} else {
43-
$log.error('Fatal error: _unlink: ' + msg)
44-
msg = 'Sorry! We are unable to remove your weblink. If problem persists, please contact <a href=\"mailTo:[email protected]\">[email protected]</a>'
45-
}
46-
47-
account.deletingAccount = false
48-
toaster.pop('error', 'Whoops!', msg)
49-
})
5055
}
5156
}
5257
}

app/directives/external-account/external-web-links.directive.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import angular from 'angular'
77
// @example <external-links-data></external-links-data>
88
angular.module('tcUIComponents').directive('externalWebLink', ExternalWebLink)
99

10-
ExternalWebLink.$inject = ['$log', 'ExternalWebLinksService', 'toaster']
10+
ExternalWebLink.$inject = ['$log', 'logger', 'ExternalWebLinksService', 'toaster']
1111

12-
function ExternalWebLink($log, ExternalWebLinksService, toaster) {
12+
function ExternalWebLink($log, logger, ExternalWebLinksService, toaster) {
1313
var directive = {
1414
restrict: 'E',
1515
template: require('./external-web-link')(),
@@ -31,6 +31,7 @@ import angular from 'angular'
3131
$log.debug('URL: ' + $scope.url)
3232
$scope.addingWebLink = true
3333
$scope.errorMessage = null
34+
3435
ExternalWebLinksService.addLink($scope.userHandle, $scope.url)
3536
.then(function(data) {
3637
$scope.addingWebLink = false
@@ -42,17 +43,19 @@ import angular from 'angular'
4243
$scope.url = null
4344
toaster.pop('success', 'Success', 'Your link has been added. Data from your link will be visible on your profile shortly.')
4445
})
45-
.catch(function(resp) {
46+
.catch(function(err) {
4647
$scope.addingWebLink = false
4748

48-
if (resp.status === 'WEBLINK_ALREADY_EXISTS') {
49+
if (err.status === 'WEBLINK_ALREADY_EXISTS') {
4950
$log.info('Social profile already linked to another account')
51+
5052
toaster.pop('error', 'Whoops!',
5153
'This weblink is already added to your account. \
5254
If you think this is an error please contact <a href=\"mailTo:[email protected]\">[email protected]</a>.'
5355
)
5456
} else {
55-
$log.error('Fatal Error: addWebLink: ' + resp.msg)
57+
logger.error('Fatal Error: addWebLink', err.msg)
58+
5659
toaster.pop('error', 'Sorry, we are unable add web link. If problem persist please contact <a href=\"mailTo:[email protected]\">[email protected]</a>.')
5760
}
5861
})

app/directives/page-state-header/page-state-header.directive.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import _ from 'lodash'
1616
hideMoney: '=',
1717
defaultState: '@'
1818
},
19-
controller: ['CONSTANTS', '$rootScope', '$scope', 'ProfileService', '$log', '$state', pageStateHeader],
19+
controller: ['CONSTANTS', '$rootScope', '$scope', 'ProfileService', '$log', 'logger', '$state', pageStateHeader],
2020
controllerAs: 'vm'
2121
}
2222
})
2323

24-
function pageStateHeader(CONSTANTS, $rootScope, $scope, ProfileService, $log, $state) {
24+
function pageStateHeader(CONSTANTS, $rootScope, $scope, ProfileService, $log, logger, $state) {
2525
var vm = this
2626
vm.backHandler = backHandler
2727

@@ -106,6 +106,8 @@ import _ from 'lodash'
106106
.catch(function(err) {
107107
$scope.hideMoney = true
108108
vm.loading = false
109+
110+
logger.error('Could not get user financial information', err)
109111
})
110112
}
111113
}

app/directives/tcui-components.module.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import angular from 'angular'
66
angular.module('tcUIComponents', ['dcbImgFallback', 'blocks.logger', 'toaster'])
77
.config(['$provide',function ($provide) {
88
$provide.decorator('$log', ['$delegate', 'LogEnhancer', function ($delegate, LogEnhancer) {
9-
LogEnhancer.enhanceLogger($delegate)
9+
LogEnhancer.enhance$log($delegate)
1010
return $delegate
1111
}])
1212
}])

app/layout/header/header.controller.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import _ from 'lodash'
66

77
angular.module('tc.layout').controller('HeaderController', HeaderController)
88

9-
HeaderController.$inject = ['$state', 'TcAuthService', 'CONSTANTS', '$log', '$rootScope', 'UserService', 'ProfileService', 'NavService']
9+
HeaderController.$inject = ['$state', 'TcAuthService', 'CONSTANTS', '$log', 'logger', '$rootScope', 'UserService', 'ProfileService', 'NavService']
1010

11-
function HeaderController($state, TcAuthService, CONSTANTS, $log, $rootScope, UserService, ProfileService, NavService) {
11+
function HeaderController($state, TcAuthService, CONSTANTS, $log, logger, $rootScope, UserService, ProfileService, NavService) {
1212
var vm = this
1313

1414
vm.constants = CONSTANTS
@@ -65,8 +65,7 @@ import _ from 'lodash'
6565
vm.userHandleColor = ProfileService.getUserHandleColor(vm.profile)
6666
})
6767
.catch(function(err) {
68-
$log.error('Unable to get user data')
69-
// todo handle error
68+
logger.error('Unable to get user profile data', err)
7069
})
7170
}
7271
}

0 commit comments

Comments
 (0)