closing connection on error