Uploaded image for project: 'Couchbase Documentation'
  1. Couchbase Documentation
  2. DOC-3711

Failure Considerations: every language have difference code example

    XMLWordPrintable

Details

    Description

      At the bottom of the page there is code sample.
      the code sample vary between languages and the getFromReplica part is reactive to a different exception which make it very difficult to determine when to use that piece of code.

      for example, .Net is reacting to KeyNotFound (which is incorrect):

      const string key = "ReplicaKey";
       var value = bucket.Get<string>(key);
       if (value.Status == ResponseStatus.KeyNotFound)
      { 
      var result = bucket.GetFromReplica<string>(key); //do something with the result
       }

       

      Java - to any Couchbase Exception (which is incorrect as well): static JsonDocument

      getOrGetReplica(Bucket bucket, String docId) { 
      try { return bucket.get(docId); 
      } catch (CouchbaseException e) {
       Iterator<JsonDocument> docs = bucket.getFromReplica(docId);
       return docs.hasNext() ? docs.next() : null; 
      } 
      }

       

      Python - to networkError:

      try:
       result = cb.get("docid")
       except CouchbaseNetworkError as e:
       print "Got error. Fetching from replica!"
       result = cb.get(‘docid’, replica=True)

      Node.js to a general couchbaseException:

      static JsonDocument getOrGetReplica(Bucket bucket, String docId) {
       try { return bucket.get(docId); }
      catch (CouchbaseException e)
      { Iterator<JsonDocument> docs = bucket.getFromReplica(docId); return docs.hasNext() ? docs.next() : null; }
      }
      

       

      It needed to be clear what is the scenario Couchbase recommending to use it.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              richard.smedley Richard Smedley
              roi.katz Roi Katz
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes

                  PagerDuty