I am assuming you have a Laravel app with axios installed.
- Run
npm install izitoast --saveto pull the iziToast - Create a
resources/assets/js/servicesfolder and placetoast.jsanderrorHandler.jsin it. - Now open the
resources/assets/js/bootstrap.jsand add following:
...
window.axios = require('axios');
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
require('./services/errorHandler');- Thats it, now you should be seeing toast notification on request fail.
You can turn off the global error handling for a specific request by passing {errorHandle: false} as config in axios call.
axios.get('/user/1', {errorHandle: false}).then((response) => {
console.log('Everything is awesome.');
}).catch((error) => {
// handle this error here
console.warn('Not good man :(');
})
This doesn't seem to work with axios 0.19.x. Any idea how to pass the errorHandle flag in the latest version of axios?