forked from colmena/colmena
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
61 lines (57 loc) · 2 KB
/
index.js
File metadata and controls
61 lines (57 loc) · 2 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
'use strict'
import angular from 'angular'
import _ from 'lodash'
import './components'
import './controllers'
import './routes'
import './services'
const NAME = 'com.module.users'
const MODULES = [
`${NAME}.components`,
`${NAME}.controllers`,
`${NAME}.routes`,
`${NAME}.services`,
]
angular.module(NAME, MODULES)
.run(($rootScope, gettextCatalog) => $rootScope
.addMenu(gettextCatalog.getString('Users'), 'app.users.list', 'fa-user'))
.config(($httpProvider) => {
// Intercept 401 responses and redirect to login screen
$httpProvider.interceptors.push(($q, $location, CoreService) => {
return {
responseError: (rejection) => {
if (rejection.status === 401) {
// $rootScope.currentUser = null
// save the current location so that login can redirect back
$location.nextAfterLogin = $location.path()
if ($location.path() === '/router' || $location.path() ===
'/login') {
console.log('401 while on router on login path')
} else {
if ($location.path() !== '/register') {
$location.path('/login')
}
CoreService.toastWarning('Error 401 received',
'We received a 401 error from the API! Redirecting to login'
)
}
}
if (rejection.status === 404) {
console.log(rejection)
CoreService.toastError('Error 404 received', _.get(rejection, 'data.error.message'))
}
if (rejection.status === 422) {
console.log(rejection)
CoreService.toastError('Error 422 received', _.get(rejection, 'data.error.message'))
}
if (rejection.status === 0) {
$location.path('/')
CoreService.toastError('Connection Refused',
'The connection to the API is refused. Please verify that the API is running!'
)
}
return $q.reject(rejection)
},
}
})
})