title: What to do with errors when streaming the body of an Http request
body: <p>How do I handle a server error in the middle of an Http message?</p>
  
  <p>Assuming I already sent the header of the message and I am streaming the 
  the body of the message, what do I do when I encounter an unexpected error.</p>
  
  <p>I am also assuming this error was caused while generating the content and not a connection error.</p>
  
  <p>(Greatly) Simplified Code:  </p>
  
  <pre><code>// I can define any transfer encoding or header fields i need to.
  send(header);  // Sends the header to the Http client.
  
  // Using an iterable instead of stream for code simplicity's sake.
  Iterable&lt;String&gt; stream = getBodyStream();
  Iterator&lt;String&gt; iterator = stream.iterator();
  
  while (iterator.hasNext()) {
      String string;
      try {
         string = iterator.next();   
      catch (Throwable error) { // Oops! an error generating the content.
          // What do i do here? (In regards to the Http protocol)
      }
  
      send(string);
  }
  </code></pre>
  
  <p>Is there a way to tell the client the server failed and should either retry or abandon the connection or am I sool?</p>
  
  <p>The code is greatly simplified but I am only asking in regards to the protocol and not the exact code.</p>
  
  <p>Thank You</p>