title: Cancelling a request with a $http interceptor?
body: <p>I'm trying to figure out if it is possible to use a <code>$http</code> interceptor to cancel a request before it even happens.</p>
  
  <blockquote>
    <p>There is a button that triggers a request but if the user double-clicks it I do not want the same request to get triggered twice.</p>
  </blockquote>
  
  <p>Now, I realize that there's several ways to solve this, and we do already have a working solution where we wrap <code>$http</code> in a service that keeps track of requests that are currently pending and simply ignores new requests with the same method, url and data.</p>
  
  <p>Basically this is the behaviour I am trying to do with an interceptor:</p>
  
  <pre><code>factory('httpService', ['$http', function($http) {
  
      var pendingCalls = {};
  
      var createKey = function(url, data, method) {
          return method + url + JSON.stringify(data);
      };
  
      var send = function(url, data, method) {
          var key = createKey(url, data, method);
          if (pendingCalls[key]) {
              return pendingCalls[key];
          }
          var promise = $http({
              method: method,
              url: url,
              data: data
          });
          pendingCalls[key] = promise;
          promise.finally(function() {
              delete pendingCalls[key];
          });
          return promise;
      };
  
      return {
          post: function(url, data) {
              return send(url, data, 'POST');
          }
      }
  
  }])
  </code></pre>
  
  <p>When I look at the API for <code>$http</code> interceptors it does not seem to be a way to achieve this. I have access to the <code>config</code> object but that's about it. </p>
  
  <p>Am I attempting to step outside the boundaries of what interceptors can be used for here or is there a way to do it?</p>