title: Where can I put global ajax error handling in Ember?
body: <p>In my application's adapter, I'm returning error codes based on ajax errors.  I'm handling these in the application route's error method.  This works great if I access a route via link-to.  But if I refresh a route or just type the URL in, my application's error handler isn't called.  Is there a place where I can put this error handling that will be guaranteed to run every time?  I really don't want to implement the same "if 401, show login" code in every single route.</p>
  
  <p>routes/application.js:</p>
  
  <pre><code>export default Ember.Route.extend({
    actions: {
      error: function(reason) {
          if (reason === 401) {
            alert('401');
              this.send('showLogin');
          }
      },
  </code></pre>
  
  <p>adapters/application.js:</p>
  
  <pre><code>import DS from 'ember-data';
  
  export default DS.ActiveModelAdapter.extend({
      'namespace': '',
    ajaxError: function(jqXHR) {
      var error = this._super(jqXHR);
      if (jqXHR &amp;&amp; jqXHR.status === 401) {
          return 401;
      }
      return error;
    }
  });
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <p>The above code nearly worked for me.  The main issue I hit was this.send('showLogin') wasn't being caught when refreshing or hitting the URL.  Changing this to a transitionTo works great:</p>
  
  <pre><code>import Ember from 'ember';
  
  export default Ember.Route.extend(ApplicationRouteMixin, {
    actions: {
      error: function(reason) {
        if (reason === 401) {
          this.transitionTo('login');
        }
      },
      ...
  </code></pre>