Modal does not handle errors on login
I have resolved it by commenting redirection code from hook_login and added redirection code related changes in ajax callback function itself. Here is my code.

function setMessage(&amp;$form, \Drupal\Core\Form\FormStateInterface $form_state) {

     $response = new AjaxResponse();
     $current= \Drupal::currentUser();
     if ($form_state-&gt;hasAnyErrors()) {
         $response-&gt;addCommand(new ReplaceCommand('#modal-form', $form));

     }
     else if (!$current-&gt;id()) {
         $response-&gt;addCommand(new ReplaceCommand('#modal-form', $form));
     }
     else {
         $command = new RedirectCommand(' ');

         return $response-&gt;addCommand($command);
     }
     return $response;
}