Better errors handling for user controller

This commit is contained in:
Bubka 2020-01-13 23:10:32 +01:00
parent 289b36d9d0
commit efc3f5d61e
8 changed files with 22 additions and 15 deletions

View File

@ -24,7 +24,7 @@ public function login(Request $request)
]);
if ($validator->fails()) {
return response()->json(['error' => $validator->errors()], 400);
return response()->json(['validation' => $validator->errors()], 400);
}
$credentials = [
@ -93,7 +93,7 @@ public function register(Request $request)
]);
if ($validator->fails()) {
return response()->json(['error' => $validator->errors()], 400);
return response()->json(['validation' => $validator->errors()], 400);
}
$input = $request->all();

2
resources/js/app.js vendored
View File

@ -67,7 +67,7 @@ const router = new VueRouter({
},
{
path: '/error',
name: 'GenericError',
name: 'genericError',
component: NotFound,
props: true
},

View File

@ -183,7 +183,10 @@
})
.catch(error => {
if (error.response.status === 404) {
this.$router.push({name: '404', params: { err : error.response }});
this.$router.push({name: '404', params: { err : error.response.data.error }});
}
else {
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
}
});
},
@ -214,7 +217,7 @@
this.$router.go('/login');
})
.catch(error => {
this.$router.push({ name: 'error' });
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
});
}
}

View File

@ -15,13 +15,13 @@
<p class="error-generic"></p>
<p>{{ $t('errors.error_occured') }}<router-link :to="{ name: 'accounts' }" class="is-text has-text-white">{{ $t('errors.refresh') }}</router-link></p>
</div>
<div v-if="debugMode == 'development'">
<!-- <div v-if="debugMode == 'development'"> -->
<p v-if="debug" class="debug">
<code>
{{ debug }}
</code>
</p>
</div>
<!-- </div> -->
</modal>
</div>
</template>
@ -34,7 +34,7 @@
data(){
return {
ShowModal : true,
debug : this.err ? this.err.data : null,
debug : this.err ? this.err : null,
}
},

View File

@ -62,11 +62,15 @@
}
})
.catch(error => {
if (error.response.status === 400) {
this.errors = error.response.data.error
console.log(error.response);
if( error.response.status === 401 ) {
this.errors['password'] = [ this.$t('auth.forms.password_do_not_match') ]
}
else if( error.response.data.validation ) {
this.errors = error.response.data.validation
}
else {
this.errors['password'] = [ this.$t('auth.forms.passwords_do_not_match') ]
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
}
});
}

View File

@ -77,7 +77,7 @@
}
})
.catch(error => {
this.$router.push({ name: 'error', params: { err: error.response.message } });
this.$router.push({ name: 'genericError', params: { err: error.response.data.message } });
});
},
@ -100,7 +100,7 @@
}
})
.catch(error => {
this.errors = error.response.data.error
this.errors = error.response.data.validation
});
}
},

View File

@ -16,7 +16,7 @@ export default {
"confirm_password": "Confirm password",
"dont_have_account_yet": "Don't have your account yet?",
"already_register": "Already registered?",
"passwords_do_not_match": "Passwords do not match"
"password_do_not_match": "Password do not match"
}
},
"commons": {

View File

@ -28,7 +28,7 @@
'confirm_password' => 'Confirm password',
'dont_have_account_yet' => 'Don\'t have your account yet?',
'already_register' => 'Already registered?',
'passwords_do_not_match' => 'Passwords do not match',
'password_do_not_match' => 'Password do not match',
]