Are you using SDK 2.x or 3.x? If 3.x, I think you can use
exception.GetType() to get a pretty good handle on the specific error, as most error codes are mapped to specific exceptions. Additionally,
CouchbaseException includes an
ErrorContext property of type
IErrorContext. This will contain a particular implementation, such as
KeyValueErrorContext depending on the type of operation you were performing, which includes much more detail.
That said, I’d personally be a bit wary of passing Couchbase error codes out from your API, architecturally speaking. Clearly, I don’t know the details of your application. But my preference is to consider the API an abstraction layer, and the database an implementation inside the black box. This gives more flexibility over the long term. For example, what if an upgrade to Couchbase adds or changes error codes, this could break your API consumers. Instead, I typically log the details of the error and return a more generic error message on the API. Again, your application might have reasons you want this, I’m speaking in generalities.