@@ -20,7 +20,6 @@ import cookie from 'js-cookie'
2020
2121import logger from './ApiLogger'
2222import notificationStore from '../stores/NotificationStore'
23- import DomUtils from '../utils/DomUtils'
2423
2524type Cancelable = {
2625 requestId : string ,
@@ -48,6 +47,13 @@ const addCancelable = (cancelable: Cancelable) => {
4847 }
4948}
5049
50+ const isOnLoginPage = ( ) : boolean => {
51+ if ( window . env . ENV === 'development' ) {
52+ return window . location . hash === '#/' || window . location . hash === '#/login'
53+ }
54+ return window . location . pathname === '/' || window . location . pathname === '/login'
55+ }
56+
5157class ApiCaller {
5258 constructor ( ) {
5359 axios . defaults . headers . common [ 'Content-Type' ] = 'application/json'
@@ -107,13 +113,11 @@ class ApiCaller {
107113 }
108114 resolve(response)
109115 } ) . catch ( error => {
110- const loginUrl = `${ DomUtils . urlHashPrefix } `
111-
112116 if ( error . response ) {
113117 // The request was made and the server responded with a status code
114118 // that falls out of the range of 2xx
115119 if (
116- ( error . response . status !== 401 || window . location . hash !== loginUrl ) &&
120+ ( error . response . status !== 401 || ! isOnLoginPage ( ) ) &&
117121 ! options . quietError &&
118122 error . response . data ) {
119123 let data = error . response . data
@@ -123,7 +127,7 @@ class ApiCaller {
123127 }
124128 }
125129
126- if ( error . response . status === 401 && window . location . hash !== loginUrl && error . request . responseURL . indexOf ( '/ proxy / ') === - 1 ) {
130+ if ( error . response . status === 401 && ! isOnLoginPage ( ) && error . request . responseURL . indexOf ( '/ proxy / ') === - 1 ) {
127131 window . location . href = '/'
128132 }
129133
@@ -138,7 +142,7 @@ class ApiCaller {
138142 } else if ( error . request ) {
139143 // The request was made but no response was received
140144 // `error.request` is an instance of XMLHttpRequest
141- if ( window . location . hash !== loginUrl ) {
145+ if ( ! isOnLoginPage ( ) ) {
142146 notificationStore . alert ( 'Request failed, there might be a problem with the connection to the server.' , 'error' )
143147 }
144148 logger.log({
0 commit comments