How to stop download in hook_file_download I'm building a page with different download buttons linked to private zip files. Users have to log in to download. I am using module Permissions by Term to manage who can see which button.
I added a field to user entity to log each download. In hook_file_download() I check, if and how often this file is already downloaded by this user. Up to here everything works fine.
I want to stop or block the download and show a message to the user, if download counter reaches 5 or 10. Is hook_file_download the right hook to achieve this?
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();
      }
    }
  }
}
  }
}