title: Session Timeout Message in RoR using Devise
body: <p>I have an application secured with devise and a session timeout of 30 minutes. With devise all is working well for normal navigation, if the user clicks on a link when timed out they get redirected back to the login screen with a message saying "Your session expired, please sign in again to continue.", excellent.</p>
  
  <p>However I have ajax in a lot of places. If the session times out and the user does an ajax operation I want the same behavior as above rather that silently failing with a 401 error in the background.</p>
  
  <p>So far I have this jquery code on each page to catch 401s and reload:</p>
  
  <pre><code>$(document).ajaxError(function(e, error) {
    switch(error.status) {
  
      case 401: {
        // unauthorised (possible timeout)
        location.reload();
        break;
      }
  </code></pre>
  
  <p>It works well enough, but there is an annoying issue:</p>
  
  <p>Because the ajax request hits devise first, when my application reloads the page I get directed to the login page, but I don't see the timeout message, I see the unauthenticated "You need to sign in or sign up before continuing." message.</p>
  
  <p>Is there a way to ensure that on the second request devise still shows the timeout message?</p>