Fix error handling and another bug in create document for cluster.