Close the connection on error