I am assuming you have a Laravel app with axios installed.
- Run
npm install izitoast --save
to pull the iziToast - Create a
resources/assets/js/services
folder and placetoast.js
anderrorHandler.js
in it. - Now open the
resources/assets/js/bootstrap.js
and 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 :(');
})
Typo in "Turn on gloabl error handling for specific call"