mirror of
https://github.com/crater-invoice/crater.git
synced 2025-10-27 11:41:09 -04:00
Merge pull request #153 from MakerLab-Dev/patch-3
Improved error handling
This commit is contained in:
22
resources/assets/js/bootstrap.js
vendored
22
resources/assets/js/bootstrap.js
vendored
@ -88,17 +88,27 @@ window.axios.interceptors.request.use(function (config) {
|
|||||||
|
|
||||||
global.axios.interceptors.response.use(undefined, function (err) {
|
global.axios.interceptors.response.use(undefined, function (err) {
|
||||||
// Do something with request error
|
// Do something with request error
|
||||||
return new Promise((resolve, reject) => {
|
if (!err.response) {
|
||||||
|
window.toastr['error']('Network error: Please check your internet connection or wait until servers are back online')
|
||||||
|
console.log('Network error: Please check your internet connection.')
|
||||||
|
} else {
|
||||||
console.log(err.response)
|
console.log(err.response)
|
||||||
if (err.response.data.error === 'invalid_credentials') {
|
|
||||||
window.toastr['error']('Invalid Credentials')
|
|
||||||
}
|
|
||||||
if (err.response.data && (err.response.statusText === 'Unauthorized' || err.response.data === ' Unauthorized.')) {
|
if (err.response.data && (err.response.statusText === 'Unauthorized' || err.response.data === ' Unauthorized.')) {
|
||||||
|
// Unauthorized and log out
|
||||||
|
window.toastr['error']((err.response.data.message) ? err.response.data.message : 'Unauthorized')
|
||||||
store.dispatch('auth/logout', true)
|
store.dispatch('auth/logout', true)
|
||||||
|
} else if (err.response.data.errors) {
|
||||||
|
// Show a notification per error
|
||||||
|
const errors = JSON.parse(JSON.stringify(err.response.data.errors))
|
||||||
|
for (const i in errors) {
|
||||||
|
window.toastr['error'](errors[i])
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw err
|
// Unknown error
|
||||||
|
window.toastr['error']((err.response.data.message) ? err.response.data.message : 'Unknown error occurred')
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
return Promise.reject(err)
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -21,13 +21,6 @@ export const login = ({ commit, dispatch, state }, data) => {
|
|||||||
window.toastr['success']('Login Successful')
|
window.toastr['success']('Login Successful')
|
||||||
resolve(response)
|
resolve(response)
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
if (err.response.data.error === 'invalid_credentials') {
|
|
||||||
window.toastr['error']('Invalid Credentials')
|
|
||||||
} else {
|
|
||||||
// Something happened in setting up the request that triggered an Error
|
|
||||||
console.log('Error', err.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
commit(types.AUTH_ERROR, err.response)
|
commit(types.AUTH_ERROR, err.response)
|
||||||
Ls.remove('auth.token')
|
Ls.remove('auth.token')
|
||||||
reject(err)
|
reject(err)
|
||||||
|
|||||||
@ -46,7 +46,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<base-button type="submit" color="theme">{{ $t('login.login') }}</base-button>
|
<base-button :loading="isLoading" type="submit" color="theme">{{ $t('login.login') }}</base-button>
|
||||||
|
|
||||||
<!-- <div class="social-links">
|
<!-- <div class="social-links">
|
||||||
|
|
||||||
@ -87,7 +87,8 @@ export default {
|
|||||||
password: '',
|
password: '',
|
||||||
remember: ''
|
remember: ''
|
||||||
},
|
},
|
||||||
submitted: false
|
submitted: false,
|
||||||
|
isLoading: false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
validations: {
|
validations: {
|
||||||
@ -98,7 +99,7 @@ export default {
|
|||||||
},
|
},
|
||||||
password: {
|
password: {
|
||||||
required,
|
required,
|
||||||
minLength: minLength(5)
|
minLength: minLength(8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -113,7 +114,6 @@ export default {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.isLoading = true
|
this.isLoading = true
|
||||||
|
|
||||||
this.login(this.loginData).then((res) => {
|
this.login(this.loginData).then((res) => {
|
||||||
this.$router.push('/admin/dashboard')
|
this.$router.push('/admin/dashboard')
|
||||||
this.isLoading = false
|
this.isLoading = false
|
||||||
|
|||||||
Reference in New Issue
Block a user