couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject chttpd commit: updated refs/heads/master to 33a242e
Date Thu, 29 Oct 2015 14:26:56 GMT
Repository: couchdb-chttpd
Updated Branches:
  refs/heads/master 5b4520b9b -> 33a242edd


Update /_replicate handler and clean it from legacy decisions

It's not actual anymore to have try/catch around replicate/2 as it never
throws any errors making catch block is actually unreached for
the specified clauses.

We also shouldn't repeat our self in error response rendering here.


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

Branch: refs/heads/master
Commit: 33a242edd90f63c5ed115e67c08b7bab640eedc2
Parents: 5b4520b
Author: Alexander Shorin <kxepal@apache.org>
Authored: Tue Oct 27 23:59:03 2015 +0300
Committer: Alexander Shorin <kxepal@apache.org>
Committed: Thu Oct 29 17:24:52 2015 +0300

----------------------------------------------------------------------
 src/chttpd_misc.erl | 40 +++++++++++++++-------------------------
 1 file changed, 15 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/33a242ed/src/chttpd_misc.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_misc.erl b/src/chttpd_misc.erl
index 1490289..ca0a033 100644
--- a/src/chttpd_misc.erl
+++ b/src/chttpd_misc.erl
@@ -143,31 +143,21 @@ handle_replicate_req(#httpd{method='POST', user_ctx=Ctx} = Req) ->
     chttpd:validate_ctype(Req, "application/json"),
     %% see HACK in chttpd.erl about replication
     PostBody = get(post_body),
-    try replicate(PostBody, Ctx) of
-    {ok, {continuous, RepId}} ->
-        send_json(Req, 202, {[{ok, true}, {<<"_local_id">>, RepId}]});
-    {ok, {cancelled, RepId}} ->
-        send_json(Req, 200, {[{ok, true}, {<<"_local_id">>, RepId}]});
-    {ok, {JsonResults}} ->
-        send_json(Req, {[{ok, true} | JsonResults]});
-    {ok, stopped} ->
-        send_json(Req, 200, {[{ok, stopped}]});
-    {error, {Type, Details}} ->
-        send_json(Req, 500, {[{error, Type}, {reason, Details}]});
-    {error, not_found} ->
-        send_json(Req, 404, {[{error, not_found}]});
-    {error, Reason} ->
-        try
-            send_json(Req, 500, {[{error, Reason}]})
-        catch
-        exit:{json_encode, _} ->
-            send_json(Req, 500, {[{error, couch_util:to_binary(Reason)}]})
-        end
-    catch
-    throw:{db_not_found, Msg} ->
-        send_json(Req, 404, {[{error, db_not_found}, {reason, Msg}]});
-    throw:{unauthorized, Msg} ->
-        send_json(Req, 404, {[{error, unauthorized}, {reason, Msg}]})
+    case replicate(PostBody, Ctx) of
+        {ok, {continuous, RepId}} ->
+            send_json(Req, 202, {[{ok, true}, {<<"_local_id">>, RepId}]});
+        {ok, {cancelled, RepId}} ->
+            send_json(Req, 200, {[{ok, true}, {<<"_local_id">>, RepId}]});
+        {ok, {JsonResults}} ->
+            send_json(Req, {[{ok, true} | JsonResults]});
+        {ok, stopped} ->
+            send_json(Req, 200, {[{ok, stopped}]});
+        {error, not_found=Error} ->
+            chttpd:send_error(Req, Error);
+        {error, {_, _}=Error} ->
+            chttpd:send_error(Req, Error);
+        {_, _}=Error ->
+            chttpd:send_error(Req, Error)
     end;
 handle_replicate_req(Req) ->
     send_method_not_allowed(Req, "POST").


Mime
View raw message