How to stop download in hook_file_download
I have this to check that the users has remaining downloads or redirect them to an upgrade page. 

/**
 * Implements hook_file_download().
 */
function mymodule_file_download($uri) {
  // Check if user is logged in
  if (\Drupal::currentUser()-&gt;isAuthenticated()) {
    // Load entity of current user
    $current_user = \Drupal\user\Entity\User::load(\Drupal::currentUser()-&gt;id());

    // Check if current user is: access || student || (professional &amp;&amp; trial_actived)
    $download_control = $current_user-&gt;hasRole('professional') &amp;&amp; $current_user-&gt;field_user_free_trial-&gt;value == 'trial_actived' ? TRUE : FALSE;
    $download_control = $download_control || $current_user-&gt;hasRole('access') || $current_user-&gt;hasRole('student') ? TRUE : FALSE;

if ($download_control) {

  // Declare files that decrease the counter
  $controlled_uris = [
    'private://mechanisms/files',
  ];

  // Check if requested uri matches with controlled uris
  foreach ($controlled_uris as $c_uri) {
    if (strpos($uri, $c_uri) !== FALSE) {

      // Check if user still has remaining downloads
      if ($current_user-&gt;field_user_download_counter-&gt;value &gt; 0) {

        // Decrease user downloads counter
        $current_user-&gt;field_user_download_counter-&gt;value--;
        $current_user-&gt;save();
      }
      else {
        // Prepare redirect url to the prices page
        $url = \Drupal\Core\Url::fromRoute('entity.node.canonical', ['node' =&gt; 39])-&gt;toString();

        // Set message
        $message = t('Your account has reached the maximum limit of downloads.');
        \Drupal::messenger()-&gt;addWarning($message);

        // Send response to url
        $response = new \Symfony\Component\HttpFoundation\RedirectResponse($url);
        $response-&gt;send();
      }
    }
  }
}
  }
}