diff options
author | John Christopher Anderson <jchris@apache.org> | 2009-05-10 19:20:23 +0000 |
---|---|---|
committer | John Christopher Anderson <jchris@apache.org> | 2009-05-10 19:20:23 +0000 |
commit | 9fe71aa326782f9dc1dc04914cd57e3b12d48af7 (patch) | |
tree | afce14f5321a729b64d4d3c778285b5b637afff0 /src/couchdb/couch_httpd_view.erl | |
parent | 2c8bc8ed6a2dc4ecdde08e779e4882f189485271 (diff) |
refactor JSON body error handling, also consolidate update_docs JSON response generation.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@773387 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_httpd_view.erl')
-rw-r--r-- | src/couchdb/couch_httpd_view.erl | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/src/couchdb/couch_httpd_view.erl b/src/couchdb/couch_httpd_view.erl index 7c13cdf2..016a391a 100644 --- a/src/couchdb/couch_httpd_view.erl +++ b/src/couchdb/couch_httpd_view.erl @@ -58,20 +58,16 @@ handle_view_req(#httpd{method='GET', handle_view_req(#httpd{method='POST', path_parts=[_Db, _Design, DName, _View, ViewName]}=Req, Db) -> - case couch_httpd:json_body(Req) of - {Fields} -> - case proplists:get_value(<<"keys">>, Fields, nil) of - nil -> - Fmt = "POST to view ~p/~p in database ~p with no keys member.", - ?LOG_DEBUG(Fmt, [DName, ViewName, Db]), - design_doc_view(Req, Db, DName, ViewName, nil); - Keys when is_list(Keys) -> - design_doc_view(Req, Db, DName, ViewName, Keys); - _ -> - throw({bad_request, "`keys` member must be a array."}) - end; + {Fields} = couch_httpd:json_body_obj(Req), + case proplists:get_value(<<"keys">>, Fields, nil) of + nil -> + Fmt = "POST to view ~p/~p in database ~p with no keys member.", + ?LOG_DEBUG(Fmt, [DName, ViewName, Db]), + design_doc_view(Req, Db, DName, ViewName, nil); + Keys when is_list(Keys) -> + design_doc_view(Req, Db, DName, ViewName, Keys); _ -> - throw({bad_request, "Body must be a JSON object"}) + throw({bad_request, "`keys` member must be a array."}) end; handle_view_req(Req, _Db) -> @@ -79,7 +75,7 @@ handle_view_req(Req, _Db) -> handle_temp_view_req(#httpd{method='POST'}=Req, Db) -> couch_stats_collector:increment({httpd, temporary_view_reads}), - {Props} = couch_httpd:json_body(Req), + {Props} = couch_httpd:json_body_obj(Req), Language = proplists:get_value(<<"language">>, Props, <<"javascript">>), {DesignOptions} = proplists:get_value(<<"options">>, Props, {[]}), MapSrc = proplists:get_value(<<"map">>, Props), |