In my setup i know there are max 3 params, so this is my solution
add_filter('request', function( $vars ) {
global $wpdb;
if(isset($vars['error'])){
$lastVar = basename($_SERVER['REQUEST_URI']);
$vars['attachment'] = $lastVar;
}
........rest off code........
}