Ignoring the default Pimcore error handler in Ext JS ajax request
Do you need to make an Ajax request but don’t want to show the default Pimcore notification popup that triggers when a request fails? In that case, you would need to bypass that default Pimcore behavior somehow. There is a way to do just that, so keep reading and find out how.
Solution
If you need to refresh your memory on how to create a JS file where your logic will be and connect it to an Event Listener so it is loaded when the Pimcore starts, you can refer to one of our older guides. In the first few steps of that guide, we explained how to do precisely that.
Now that we have a place for our JS code ready, let’s overwrite that default behavior. In order to have Pimcore not show the default notification popup for failed Ajax request, it is enough to simply add a new property to your Ajax request called ignoreErrors and set it to true like in the example below:
It works like this because, in the file: vendor/pimcore/pimcore/bundles/AdminBundle/Resources/public/js/pimcore/startup.js, there is a global ajax event Ext.Ajax.on('requestexception'...) where this logic is defined. Inside it, you can see that the value of options["ignoreErrors"] is checked, and only if it is true, the logic for showing the notification will trigger. By setting our ignoreErrors property to false, we simply skip everything inside.
Does it work?
To test it, you just need to trigger your Ajax request and ensure it fails. And this time, you will not see that default Pimcore notification.
Do you have more questions, or have issues while implementing this? Reach out to us; we’ll be glad to help!