python-cloudant document update error handling

362 Views Asked by At

i've just started using the python-cloudant library for my couchdb related database queries. I implemented a module for database connection. However i'm not sure how to use the python-cloudant errors documentation to help me tell when an operation fails. Forexample i'm updating a document and i really don't know if the operation was successful or not. Below is my database connection module.

couchmodule.py

class CouchdbAk:
    def __init__(self):
        self.client = self.connect()
        self.db = self.opendb()
        self.filemodule = FileModule()

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.client.disconnect()

    def connect(self):
        return CouchDB(constants.USERNAME, constants.PASSWORD, account=constants.ACCOUNT_NAME, url=constants.DBHOST,
                       connect=True, auto_renew=True)

    def disconnect(self):
        self.client.disconnect()

    def opendb(self):
        return self.client[constants.DBNAME]

    def updatedoc(self, id, newvalues):

        doc = self.db[id]
        for key in newvalues:
            doc[key] = newvalues[key]
        doc.save()
0

There are 0 best solutions below