couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r1043960 - in /couchdb/branches/new_replicator/src/couchdb: couch_api_wrap.erl couch_httpd_rep.erl couch_replicator.erl
Date Thu, 09 Dec 2010 13:20:02 GMT
Author: fdmanana
Date: Thu Dec  9 13:20:02 2010
New Revision: 1043960

URL: http://svn.apache.org/viewvc?rev=1043960&view=rev
Log:
New replicator: improved error reporting and made it more similar to the old replicator

Modified:
    couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl
    couchdb/branches/new_replicator/src/couchdb/couch_httpd_rep.erl
    couchdb/branches/new_replicator/src/couchdb/couch_replicator.erl

Modified: couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl?rev=1043960&r1=1043959&r2=1043960&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl Thu Dec  9 13:20:02 2010
@@ -74,26 +74,26 @@ db_open(#httpdb{} = Db1, _Options, Creat
         (401, _, _) ->
             throw({unauthorized, ?l2b(db_uri(Db))});
         (_, _, _) ->
-            throw({db_not_found, ?l2b(Db#httpdb.url)})
+            throw({db_not_found, ?l2b(db_uri(Db))})
         end);
 db_open(DbName, Options, Create) ->
-    case Create of
-    false ->
-        ok;
-    true ->
-        case couch_db:create(DbName, Options) of
-        {ok, _Db} ->
+    try
+        case Create of
+        false ->
             ok;
-        file_exists ->
-            ok
+        true ->
+            ok = couch_httpd:verify_is_server_admin(
+                get_value(user_ctx, Options)),
+            couch_db:create(DbName, Options)
+        end,
+        case couch_db:open(DbName, Options) of
+        {not_found, _Reason} ->
+            throw({db_not_found, DbName});
+        {ok, _Db} = Success ->
+            Success
         end
-    end,
-    case (catch couch_db:open(DbName, Options)) of
-    {not_found, _Reason} ->
-        throw({db_not_found, DbName});
-    {ok, _Db2} = Success ->
-        Success;
-    {unauthorized, _} ->
+    catch
+    throw:{unauthorized, _} ->
         throw({unauthorized, DbName})
     end.
 

Modified: couchdb/branches/new_replicator/src/couchdb/couch_httpd_rep.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_httpd_rep.erl?rev=1043960&r1=1043959&r2=1043960&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_httpd_rep.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_httpd_rep.erl Thu Dec  9 13:20:02 2010
@@ -19,6 +19,10 @@
     send_json/3,
     send_method_not_allowed/2
 ]).
+
+-import(couch_util, [
+    to_binary/1
+]).
     
 -export([handle_req/1]).
 
@@ -27,13 +31,12 @@ handle_req(#httpd{method = 'POST', user_
     RepDoc = couch_httpd:json_body_obj(Req),
     {ok, Rep} = couch_replicator_utils:parse_rep_doc(RepDoc, UserCtx),
     case couch_replicator:replicate(Rep) of
+    {error, {Error, Reason}} ->
+        send_json(
+            Req, 404,
+            {[{error, to_binary(Error)}, {reason, to_binary(Reason)}]});
     {error, Reason} ->
-        try
-            send_json(Req, 500, {[{error, Reason}]})
-        catch
-        exit:{json_encode, _} ->
-            send_json(Req, 500, {[{error, couch_util:to_binary(Reason)}]})
-        end;
+        send_json(Req, 500, {[{error, to_binary(Reason)}]});
     {ok, {cancelled, RepId}} ->
         send_json(Req, 200, {[{ok, true}, {<<"_local_id">>, RepId}]});
     {ok, {continuous, RepId}} ->

Modified: couchdb/branches/new_replicator/src/couchdb/couch_replicator.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_replicator.erl?rev=1043960&r1=1043959&r2=1043960&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_replicator.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_replicator.erl Thu Dec  9 13:20:02 2010
@@ -153,8 +153,8 @@ start_replication(#rep{id = {BaseId, Ext
             ?LOG_DEBUG("replication ~p already running at ~p",
                 [RepChildId, Pid]),
             {ok, Pid};
-        {error, _} = Err ->
-            Err
+        {error, _} = Error ->
+            Error
         end;
     {error, {already_started, Pid}} ->
         ?LOG_DEBUG("replication ~p already running at ~p", [RepChildId, Pid]),
@@ -198,6 +198,11 @@ init(InitArgs) ->
     try
         do_init(InitArgs)
     catch
+    throw:{unauthorized, DbUri} ->
+        {stop, {unauthorized,
+            <<"unauthorized to access database ", DbUri/binary>>}};
+    throw:{db_not_found, DbUri} ->
+        {stop, {db_not_found, <<"could not open ", DbUri/binary>>}};
     throw:Error ->
         {stop, Error}
     end.



Mime
View raw message