Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

New replicator: improved error reporting and made it more similar to …

…the old replicator

git-svn-id: https://svn.apache.org/repos/asf/couchdb/branches/new_replicator@1043960 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
commit bff69064ae6d1e330dc2833314dbeb8f2e680276 1 parent 2c937d9
@fdmanana fdmanana authored
View
32 src/couchdb/couch_api_wrap.erl
@@ -74,26 +74,26 @@ db_open(#httpdb{} = Db1, _Options, Create) ->
(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.
View
15 src/couchdb/couch_httpd_rep.erl
@@ -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_ctx = UserCtx} = Req) ->
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}} ->
View
9 src/couchdb/couch_replicator.erl
@@ -153,8 +153,8 @@ start_replication(#rep{id = {BaseId, Extension}} = Rep) ->
?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.
Please sign in to comment.
Something went wrong with that request. Please try again.