code: static public void captureReponseErrors(Object response, String errorMessage) throws Exception {
  		if( null == response ) {
  			throw new Exception("Capturing errors from null response");
  		}
  		if( false == (response instanceof JSONObject) ) {
  			// Not an error
  			return;
  		}
  		JSONObject obj = (JSONObject)response;
  		if( JSONSupport.containsKey(obj,"error") ) {
  			String serverMessage;
  			try {
  				serverMessage = obj.getString("error");
  			} catch (Exception e) {
  				serverMessage = "Unable to parse error response";
  			}
  			
  			if( null == errorMessage ) {
  				errorMessage = "Error returned by database: ";
  			}
  			throw new Exception(errorMessage+serverMessage);
  		}
  	}
docs: Analyze a CouchDb response and raises an exception if an error was returned
  in the response.
  @param response JSON response sent by server
  @param errorMessage Message of top exception
  @throws Exception If error is returned in response