I am creating an application: Laravel as backend and Vue as frontend. For responses in case of validation errors I use code 422 (according to the recommendations from this article).
My PHP code (form RegisterController):
if ($this->validator($request->all())->fails()) {
return response()->json(['errors'=>$this->validator($request->all())->errors()], 422);
}
In my Vue application I am using Vuex. My SignUp action looks like that:
const actions = {
ACTION_SIGN_UP: async (context, payload) => {
Axios
.post('/api/v1/register', payload)
.then((response) => {
console.log(response);
})
.catch((error) => {
if (error.response) {
console.log(error.response.data);
console.log(error.response.status);
console.log(error.response.headers);
} else if (error.request) {
console.log(error.request);
} else {
console.log('Error', error.message);
}
console.log(error.config);
});
}
};
The error is handled, but at the same time an error message appears in the console:
So how to prevent console message?