PFA patch to extract the common code from query tool to handle ajax errors & connection handling, Also added unit tests around extracted code.
Looks good to me, except, I wonder if we should rename is_new_transaction_required.js/is_new_transaction_required_spec.js to something a little more generic; maybe conn_tx_handler_funcs.js? Not sure I like that though.