How to disable drupal ajax error alerts

Its really annoying for a site visitor to come across errors whether be it php or javascript error. Drupal by default shows an error using javascript alert() function if there is a problem during Drupal ajax request.

The alert text is something like

An AJAX HTTP request terminated abnormally.
Debugging information follows.
Path: /system/ajax

Good thing is we can disable it by using Drupal javascript behavior and instead of showing an alert, it will write the error message to the browser console.

(function($) {
  Drupal.behaviors.disableAlerts = {
    attach: function(context, settings) {
      window.alert = function(text) { //override alert() function
        if(typeof console != "undefined") {
          console.error('Error: ' + text);
        return true;