Handling errors

I’ve read this article Handling Errors with the .NET SDK | Couchbase Docs

Where can I find a list of all possible errors that I can catch for each method?
If I’m using the SDK to build a webAPI, is there no errorID per error type that I can return in the json response so that the client consuming it won’t have to search for specific text inside error messages?


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.

1 Like

Thanks for the detailed answer.
Unfortunately I have to consume this webAPI in a classic ASP enterprise web app and set some global Application variables based on specific errors from Couchbase which might indicate a continuous disruption of service…