I’m using “couchbase”: “^4.3.1” in my Node.js application. We use Couchbase as a caching mechanism (2 hours) for some data received from another endpoint.
I observed that once a document expires (or it doesn’t exist), when querying non-existent keys from the primary node, I receive DocumentNotFoundError as expected. However, based on the current code, we’re also querying the replicas 2 times (using getAnyReplica). For the same non-existent keys, I consistently receive DocumentUnretrievableError from the replicas.
No matter if I call the replica with a fresh key or an expired one, the response from getAnyReplica is the same error:
I want to modify the code a little bit to make it handle the responses more gracefully and I’m in a dilemma if doing something like this if (error instanceof DocumentNotFoundError || error instanceof DocumentUnretrievableError) { would be a correct approach.
Is throwing DocumentUnretrievableError expected? If not, how would you recommend I handle DocumentUnretrievableError?
Yes this is expected. A regular non-replica collection.get() call will fail with DocumentNotFoundError, while if a collection.getAnyReplica() call fails with any reason (including that a document wasn’t present), then DocumentUnretrievableError is raised.
Just to confirm, is there any scenario where the collection.getAnyReplica() call would respond with DocumentNotFoundError or is always the UnretrievableError?