I am checking to see if a resource exists via Axios, it is normal to expect a 404 to be returned if it is not present.
But, when the 404 is returned, it is displayed in the console. I have tried to catch the error, but this does not prevent it from being displayed by chrome.
axios.get('/api/user/checkin').then((response) => {
Vue.set(UserStore,'checkin', response.data)
this.loading = false;
}).catch((error) =>{})
I am checking to see if the user is checked if they are I will return a record of when they checked in and some details on the site.
If they are not then I have nothing to return so I am returning a 404. I could return a blank record but that does feel very restful.
Update the function in the Search component inside Search. js. This approach works to remove the console errors from Axios that return 404 error in the console.
By default, axios throws an error when it encounters any 4XX / 5XX status code. Adding this line overrides that default behavior. You can then check the status code yourself (in response. status ), conditionally handling the 404 as you need.
error. Note: This occurs when the browser was able to initiate a request but did not receive a valid answer for any reason. Earlier we mentioned that the underlying request Axios uses depends on the environment in which it's being run. This is also the case for the err. request object.
Alternatively you can call console. clear() to remove all existing items within the console. However I wouldn't advise doing either of these. A much better approach would be to fix your codebase so that you avoid errors and implement graceful error handling where unexpected errors may occur.
This is a chrome behavior. see this and also this.
You can do console.clear()
in catch as suggested by this answer.
axios.get('/api/user/checkin')
.then((response) => {
Vue.set(UserStore,'checkin', response.data)
this.loading = false;
})
.catch(() => console.clear()) // this will clear any console errors caused by this request
or.catch(console.clear)
for short.
But be aware that you will lose any previous console logs.
Edit:
You may want to clear the console when you receive a 404 response only.
axios.get('/api/user/checkin')
.then((response) => {
Vue.set(UserStore,'checkin', response.data)
this.loading = false;
})
.catch((error) => {
if(error.response && error.response.status === 404) {
console.clear();
}
})
Refer to handling errors in Axios for more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With