couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robertkowal...@apache.org
Subject [01/50] [abbrv] couchdb-mango git commit: Check `mango_crud:insert/3` return values
Date Tue, 03 Feb 2015 15:13:08 GMT
Repository: couchdb-mango
Updated Branches:
  refs/heads/master [created] 09e4b815d


Check `mango_crud:insert/3` return values

The wrapped `{ok, _}` tuple can be misleading on what's returned. This
checks the actual values more closely so that clients aren't confused
when an index creation fails.

BugzId: 31919


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

Branch: refs/heads/master
Commit: 83fb0db3b99dabb7b82c412a3afe3265b4aedff4
Parents: 9e91d75
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
Authored: Tue Jun 24 14:56:02 2014 -0500
Committer: Paul J. Davis <paul.joseph.davis@gmail.com>
Committed: Tue Jun 24 14:56:02 2014 -0500

----------------------------------------------------------------------
 src/mango_error.erl | 19 +++++++++++++++++++
 src/mango_httpd.erl |  9 +++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/83fb0db3/src/mango_error.erl
----------------------------------------------------------------------
diff --git a/src/mango_error.erl b/src/mango_error.erl
index 2c4a53c..f34dac5 100644
--- a/src/mango_error.erl
+++ b/src/mango_error.erl
@@ -54,6 +54,25 @@ info(mango_fields, {invalid_field_json, BadField}) ->
         fmt("Invalid JSON for field spec: ~w", [BadField])
     };
 
+info(mango_httpd, error_saving_ddoc) ->
+    {
+        500,
+        <<"error_saving_ddoc">>,
+        <<"Unknown error while saving the design document.">>
+    };
+info(mango_httpd, {error_saving_ddoc, <<"conflict">>}) ->
+    {
+        500,
+        <<"error_saving_ddoc">>,
+        <<"Encountered a conflict while saving the design document.">>
+    };
+info(mango_httpd, {error_saving_ddoc, Reason}) ->
+    {
+        500,
+        <<"error_saving_ddoc">>,
+        fmt("Unknown error while saving the design document: ~s", [Reason])
+    };
+
 info(mango_idx, {invalid_index_type, BadType}) ->
     {
         400,

http://git-wip-us.apache.org/repos/asf/couchdb-mango/blob/83fb0db3/src/mango_httpd.erl
----------------------------------------------------------------------
diff --git a/src/mango_httpd.erl b/src/mango_httpd.erl
index eb4f60e..36ebd91 100644
--- a/src/mango_httpd.erl
+++ b/src/mango_httpd.erl
@@ -50,8 +50,13 @@ handle_index_req(#httpd{method='POST', path_parts=[_, _]}=Req, Db) ->
             <<"exists">>;
         {ok, NewDDoc} ->
             case mango_crud:insert(Db, NewDDoc, [{w, "3"} | Opts]) of
-                {ok, _} ->
-                    <<"created">>;
+                {ok, [{RespProps}]} ->
+                    case lists:keyfind(error, 1, RespProps) of
+                        {error, Reason} ->
+                            ?MANGO_ERROR({error_saving_ddoc, Reason});
+                        _ ->
+                            <<"created">>
+                    end;
                 _ ->
                     ?MANGO_ERROR(error_saving_ddoc)
             end


Mime
View raw message