title: Throwing an Error in jQuery's Deferred object
body: <p>I have an <a href="http://api.jquery.com/jQuery.ajax/" rel="noreferrer"><code>$.ajax</code></a> promise and want to check whether my (syntactically valid) response contains an error, triggering the rejected status in that case.</p>
  
  <p>I have worked with my own promise library which deals such tasks easily. I do not really like jQuery's <a href="http://wiki.commonjs.org/wiki/Promises/A" rel="noreferrer">Promise</a> (<a href="http://webcache.googleusercontent.com/search?q=cache:wiki.commonjs.org/wiki/Promises/A" rel="noreferrer">cache</a>) implementation with its <a href="http://api.jquery.com/category/deferred-object/" rel="noreferrer"><code>Deferred</code> object</a> and may have overlooked something, because I seldom use it. I think the way to go is just using <a href="http://api.jquery.com/deferred.then/" rel="noreferrer"><code>.then()</code></a>, which seems to be rather complicated:</p>
  
  <pre><code>return $.ajax(...).then(function success(response) {
      var problem = hasError(response);
      if (problem) {
          var error = new $.Deferred;
          error.reject(problem);
          return error;
      } else
          return response;
  });
  </code></pre>
  
  <p>This should return a promise which is rejected in case of network errors or problems with the response. But is returning a rejected deferred really the [only|best|shortest] way to go?</p>
  
  <p>I also would appriciate help on how to deal with such "error-throwing response handlers" in the ajax options themselfes, I could not find good documentation about them.</p>
  
  <hr>
  
  <p>Disclaimer: No, I cant change the server responses. The problem-detecting method is synchronous. I don't want to use other libraries, I'm particularly interested in the way jQuery solves this.</p>