Hitting the back button after a batch process cause a nasty error I have a batch process (using batch API) that runs when a user on my site tries to launch a non signed Java applet. The batch process does all the needed codesigning and other things and then redirects the user to the applet when it is finished. This all works well but if the user hits back from the applet page they get this nasty error with the text from my batch_error function.



It seems that this occurs because when you hit back you end up trying to run a batch process that no longer exists. Is there anyway to avoid this?

EDIT:

Here is my function that sets up the batch process:

function batch_codesign($node) {
$batch = array(
   'operations' =&gt; array(
        array('batch_codesign_process', array("create_jar_files", $node)),
        array('batch_codesign_process', array("output_new_agentsheets_applet_html", $node)),
    ),
    'finished' =&gt; 'batch_codesign_finished',
    'title' =&gt; t('Codesigning'),
    'init_message' =&gt; t('Codesigning ' . $node-&gt;title .'.'),
    'progress_message' =&gt; t('Processed @current out of @total.'),
    'error_message' =&gt; t('An error has occured while condesigning the project, please try again.'),    
    );
batch_set($batch);
$nid = $node-&gt;nid;
batch_process("path/to/endpoint");
}
Here's a possible solution, however you'll need to alter the menu callback for patch and wrap the default page callback.

Create your hook_menu_alter() and change batch to be your own page callback function, and update the file attribute (unset if in your .module)

  // Default page for batch operations.
    $items['batch'] = array(
      'page callback' =&gt; 'system_batch_page',
      'file' =&gt; 'system.admin.inc',
    );


Basically your callback can mimic around the default system_batch_page() page callback. From there you can adjust what happens when someone hits an inactive or stale batch.