mirror of
				https://github.com/crater-invoice/crater.git
				synced 2025-10-31 13: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) { | ||||
|   // 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) | ||||
|     if (err.response.data.error === 'invalid_credentials') { | ||||
|       window.toastr['error']('Invalid Credentials') | ||||
|     } | ||||
|     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) | ||||
|     } 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 { | ||||
|       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') | ||||
|       resolve(response) | ||||
|     }).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) | ||||
|       Ls.remove('auth.token') | ||||
|       reject(err) | ||||
|  | ||||
| @ -46,7 +46,7 @@ | ||||
|       </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"> | ||||
|  | ||||
| @ -87,7 +87,8 @@ export default { | ||||
|         password: '', | ||||
|         remember: '' | ||||
|       }, | ||||
|       submitted: false | ||||
|       submitted: false, | ||||
|       isLoading: false | ||||
|     } | ||||
|   }, | ||||
|   validations: { | ||||
| @ -98,7 +99,7 @@ export default { | ||||
|       }, | ||||
|       password: { | ||||
|         required, | ||||
|         minLength: minLength(5) | ||||
|         minLength: minLength(8) | ||||
|       } | ||||
|     } | ||||
|   }, | ||||
| @ -113,7 +114,6 @@ export default { | ||||
|       } | ||||
|  | ||||
|       this.isLoading = true | ||||
|  | ||||
|       this.login(this.loginData).then((res) => { | ||||
|         this.$router.push('/admin/dashboard') | ||||
|         this.isLoading = false | ||||
|  | ||||
		Reference in New Issue
	
	Block a user