[Vuejs]-How should i catch and handle 406 error in VUEJS

0๐Ÿ‘

You can simply wrap an api call into try-catch and simply donโ€™t to do anything with e in catch part.

try { ... you code here ... } catch(e){}

0๐Ÿ‘

If you are using Axios for API calls you can create a global interceptor and return a response based on your status code to your component.
This would go in your main.js.

axios.interceptors.response.use(null, function(error) {
    console.log(error);
 if(err.response.status === 406){
       //your code here.
    }
    return Promise.reject(error);
});

0๐Ÿ‘

you can wrap your call in a try{} catch(e) {} to handle what happens after the error happens

but it is impossible to prevent the browser from showing the error in the console programmatically because of the potential risk that a script might misuse the errored requests to hide its activities from the user.

0๐Ÿ‘

check_time(day,hour){
    var fields = {};
    fields.day = parseInt(day);
    fields.hour = parseInt(hour);

    try {
        this.$http.post('courses/check', fields)
    } catch {
        this.$store.dispatch('alert', {'message': 'Already exist a course in this interval.'});
    }

}

Leave a comment