I'm using flask for development, not production, and i have a view for an ajax request, something like this:
@application.route('/xyz/<var>/', methods=['GET'])
def getAjax(var):
...
return render_template(...)
I'm also using threaded=true
for development.
Whenever i call that ajax request and then just close the tab that requested it i get an error:
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
Can i have a try: except
block to catch this exception?
I tried putting all of the getAjax
function's contents on a:
try:
...
except socket.error, e:
logging.warn("socket error " + e)
But it's not working, where should i do this? or how?
EDIT: adding the ajax call
$.ajax({
type: 'GET',
url: '/xyz/' + var + '/',
data: {
...
},
timeout: 2000,
success: function(data) {
...
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
...
}
});