title: Can I manually resolve a deferred object if a callback might need to reject it?
body: <p>I'm trying to use a custom deferred object to manage some callbacks. I've figured out the easy case:</p>
  
  <pre><code>var deferred = $.Deferred();
  
  deferred.done(function() {
      console.log( 'done' );
  });
  
  var json = $.getJSON('/foo');
  
  json.then(
      function() {
          deferred.resolveWith(this, arguments);
      }  
  );
  </code></pre>
  
  <p>But I need to inspect the response before resolving/rejecting. I'd like to add something like this:</p>
  
  <pre><code>deferred.pipe(
      function(response) {
          if (response.message === 'error') {
              return $.Deferred.reject(response);
          }
          return response;
      }
  );
  </code></pre>
  
  <p>But when I do, my original <code>done()</code> callback is always called regardless. I'm pretty sure it's because once I call <code>deferred.resolveWith()</code> it's too late to "roll back" and mark it as rejected later. I know I could just move the conditional up into the first argument to <code>json.then()</code>, but that seems to miss the point of a deferred object -- I thought they were meant for encapsulating all of these behaviors into a single place.</p>
  
  <p>Is it possible to put both the conditional and the callback into <code>deferred</code> while still resolving it elsewhere?</p>