Search:

Search all manuals
Search this manual
Manual
Couchbase Developer's Guide 2.0
Community Wiki and Resources
Download Couchbase Server 2.0
Couchbase Server 2.0 Manual
Client Libraries
Couchbase Server Forum
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
4 Finding Data with Views
Chapter Sections
Chapters

4.12. Error Handling for Views

When you query a view, Couchbase Server might return errors when it is generating a result set. For instance, the server may only be able to retrieve results from two of three server nodes in response to a view query. Couchbase Server will include any successfully created results as a JSON object; any errors that the server encountered are a part of the JSON object. Couchbase SDKs include helper methods you can use to handle any detected errors. For instance in the Ruby SDK:

view = blog.recent_posts(:include_docs => true)
logger = Logger.new(STDOUT)

view.on_error do |from, reason|
  logger.warn("#{view.inspect} received the error '#{reason}' from #{from}")
end

posts = view.each do |doc|
  # do something
  # with doc object
end

We start by querying our view and assigning the result set to the variable view. We then use the on_error method to intercept any error objects that are streaming from Couchbase Server in response to the view query. Within the on_error loop we can do something useful with each error object; in this case we log the content from the error object to standard output.

Note that any error objects in a result set will appear at the end of the response object. Therefore you may receive several objects in the result set that are successfully retrieved results. After any retrieved results you will find error objects.

If you are using the REST API or Couchbase Admin Console to query views, you can read more about the functional equivalent of the on_error method and what conditions will cause errors here: Couchbase Server 2.0 Manual, Views, Error Control.