couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [1/5] chttpd commit: updated refs/heads/COUCHDB-3288-remove-public-db-record to 27cadc5 [Forced Update!]
Date Wed, 22 Feb 2017 16:06:03 GMT
Repository: couchdb-chttpd
Updated Branches:
  refs/heads/COUCHDB-3288-remove-public-db-record dddab3f08 -> 27cadc58d (forced update)


Handle error return clauses for fabric:open_revs

When calling fabric:open_revs, we don't account for situations where
the function returns an {error, any()} value as specified by the
function specification. This will account for errors thrown.

COUCHDB-3289


Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/cd4c5c70
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/cd4c5c70
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/cd4c5c70

Branch: refs/heads/COUCHDB-3288-remove-public-db-record
Commit: cd4c5c70c146e74a344b42e7e636e8e81f08495c
Parents: 90648a2
Author: Tony Sun <tony.sun@cloudant.com>
Authored: Wed Feb 1 13:14:42 2017 -0800
Committer: Tony Sun <tony.sun@cloudant.com>
Committed: Wed Feb 1 13:14:42 2017 -0800

----------------------------------------------------------------------
 src/chttpd_db.erl | 37 ++++++++++++++++++++++---------------
 1 file changed, 22 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/cd4c5c70/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index f3dd2ab..bb08db6 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -673,11 +673,10 @@ db_doc_req(#httpd{method='GET', mochi_req=MochiReq}=Req, Db, DocId)
->
         Doc = couch_doc_open(Db, DocId, Rev, Options2),
         send_doc(Req, Doc, Options2);
     _ ->
-        {ok, Results} = fabric:open_revs(Db, DocId, Revs, Options),
-        case Results of
-            [] when Revs == all ->
+        case fabric:open_revs(Db, DocId, Revs, Options) of
+            {ok, []} when Revs == all ->
                 chttpd:send_error(Req, {not_found, missing});
-            _Else ->
+            {ok, Results} ->
                 case MochiReq:accepts_content_type("multipart/mixed") of
                 false ->
                     {ok, Resp} = start_json_response(Req, 200),
@@ -703,7 +702,9 @@ db_doc_req(#httpd{method='GET', mochi_req=MochiReq}=Req, Db, DocId) ->
                     end_json_response(Resp);
                 true ->
                     send_docs_multipart(Req, Results, Options)
-                end
+                end;
+            {error, Error} ->
+                chttpd:send_error(Req, Error)
         end
     end;
 
@@ -722,7 +723,10 @@ db_doc_req(#httpd{method='POST', user_ctx=Ctx}=Req, Db, DocId) ->
         Doc = couch_doc_from_req(Req, DocId, Json);
     false ->
         Rev = couch_doc:parse_rev(list_to_binary(couch_util:get_value("_rev", Form))),
-        {ok, [{ok, Doc}]} = fabric:open_revs(Db, DocId, [Rev], [])
+        Doc = case fabric:open_revs(Db, DocId, [Rev], []) of
+            {ok, [{ok, Doc0}]} -> Doc0;
+            {error, Error} -> throw(Error)
+        end
     end,
     UpdatedAtts = [
         couch_att:new([
@@ -1063,14 +1067,16 @@ couch_doc_open(#db{} = Db, DocId, Rev, Options0) ->
          Error ->
              throw(Error)
          end;
-  _ -> % open a specific rev (deletions come back as stubs)
-      case fabric:open_revs(Db, DocId, [Rev], Options) of
-          {ok, [{ok, Doc}]} ->
-              Doc;
-          {ok, [{{not_found, missing}, Rev}]} ->
-              throw(not_found);
-          {ok, [Else]} ->
-              throw(Else)
+    _ -> % open a specific rev (deletions come back as stubs)
+        case fabric:open_revs(Db, DocId, [Rev], Options) of
+        {ok, [{ok, Doc}]} ->
+            Doc;
+        {ok, [{{not_found, missing}, Rev}]} ->
+            throw(not_found);
+        {ok, [Else]} ->
+            throw(Else);
+        {error, Error} ->
+            throw(Error)
       end
   end.
 
@@ -1235,7 +1241,8 @@ db_attachment_req(#httpd{method=Method, user_ctx=Ctx}=Req, Db, DocId,
FileNamePa
         Rev ->
             case fabric:open_revs(Db, DocId, [Rev], [{user_ctx,Ctx}]) of
             {ok, [{ok, Doc0}]}  -> Doc0;
-            {ok, [Error]}       -> throw(Error)
+            {ok, [Error]}       -> throw(Error);
+            {error, Error}      -> throw(Error)
             end
     end,
 


Mime
View raw message