title: Dart Client HttpRequest error/authentication handling
body: <p>I have a Dart client and a Java backend.  I'm trying to add security around my application, so the Java server requires the user to be authenticated before accessing data.  If a webservice call comes in and the user is not authenticated the backend services send a redirect with a HttpResponseCode (401) back to the client call.  I have it now that the client can parse the request.status and see the 401 but it doesn't handle the redirect.</p>
  
  <p>Dart Code</p>
  
  <pre><code>HttpRequest request=new HttpRequest();
    request.onReadyStateChange.listen((_) {
      if (request.readyState == HttpRequest.DONE &amp;&amp;
          (request.status == 200 || request.status == 0)) {
        onHistoryLoaded(request.responseText);
      }
    });
  
    request.open("GET", url);
    request.send();
    request.onLoadEnd.listen((e) =&gt; processRequest(request));
    request.onError.listen((Object error)=&gt;handleError(error));
  
  void processRequest(HttpRequest request) {
    var status = request.status;
    print("status $status"); //401
  }
  
  void handleTheError(Error e){
    print("handleTheError Request error: $e");
  }
  </code></pre>
  
  <p>Java Server</p>
  
  <pre><code>//Tried both of these
  //    response.setStatus(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED);
  //    response.sendRedirect(LOGIN_PAGE);
  
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        response.setHeader("Location", LOGIN_PAGE);
  </code></pre>
  
  <p>Any suggestions would be great.
  Thanks</p>