add connection close code when got an error in server side