title: how to make an exception for broken pipe errors on flask, when the client disconnects prematurely?
body: <p>I'm using flask for development, not production, and i have a view for an ajax request, something like this:</p>
  
  <pre><code>@application.route('/xyz/&lt;var&gt;/', methods=['GET'])
  def getAjax(var):
      ...
      return render_template(...)
  </code></pre>
  
  <p>I'm also using <code>threaded=true</code> for development.
  Whenever i call that ajax request and then just close the tab that requested it i get an error:</p>
  
  <pre><code>Traceback (most recent call last):   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 593, in process_request_thread
  self.finish_request(request, client_address)   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 334, in finish_request
  self.RequestHandlerClass(request, client_address, self)   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 651, in __init__ 2015-07-07 09:46:09,430 127.0.0.1 - - [07/Jul/2015 09:46:09] "GET /xyz/List/ HTTP/1.1" 200 -
  self.finish()   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/SocketServer.py", line 710, in finish
  self.wfile.close()   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 279, in close
  self.flush()   File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 303, in flush
  self._sock.sendall(view[write_offset:write_offset+buffer_size]) error: [Errno 32] Broken pipe
  </code></pre>
  
  <p>Can i have a <code>try: except</code> block to catch this exception?
  I tried putting all of the <code>getAjax</code> function's contents on a:</p>
  
  <pre><code>try:
      ...
  except socket.error, e:
      logging.warn("socket error " + e)
  </code></pre>
  
  <p>But it's not working, where should i do this? or how?</p>
  
  <p>EDIT: adding the ajax call</p>
  
  <pre><code>$.ajax({
      type: 'GET',
      url: '/xyz/' + var + '/',
      data: {
              ...
          },
      timeout: 2000,
      success: function(data) {
          ...
          },
      error: function(XMLHttpRequest, textStatus, errorThrown) {
          ...
          }
      });
  </code></pre>