How to handle exceptions in a batch process I have some special configured content entities in my system which are protected in a pre-delete hook against entity deletion.
There is also a batch process (VBO - entity delete) where they can be selected before hand. 

I want to handle gracefully the exception in a batch process which wasn't written by me (and cannot be touched). I tried to subscribe to the exception event and look for xmlHttpRequest which was all fine, but then I dunno what response to set back to stop the process, or log the exception within the batch process with the proper message. What I always get back is this, where the error message is what I put into the AjaxResponse body:



Any help appreciated find a more sophisticated solution to redirect from the batch processing in case of an exception.
So in the end I took and overrode the plugin provided by the VBO.
This will put the exception message into the summary displayed with a drupal_set_message at the end of the batch process (VBO 3.0.0-alpha2).
    

namespace Drupal\my_module\Plugin\Action;

use Drupal\views_bulk_operations\Plugin\Action\EntityDeleteAction;

/**
 * Delete entity action with default confirmation form.
 *
 * @Action(
 *   id = "my_module_delete_entity",
 *   label = @Translation("MyModule Delete selected entities"),
 *   type = "",
 *   confirm = TRUE,
 * )
 */
class MyModuleEntityDeleteAction extends EntityDeleteAction {

  public function execute($entity = NULL) {
    try {
      $entity-&gt;delete();
      return $this-&gt;t('Delete entities');
    }
    catch (\Exception $e) {
      return $e-&gt;getMessage();
    }
  }

}