diff options
author | John Christopher Anderson <jchris@apache.org> | 2009-04-18 20:15:44 +0000 |
---|---|---|
committer | John Christopher Anderson <jchris@apache.org> | 2009-04-18 20:15:44 +0000 |
commit | 3e47bfd6586f42f9fe8e49cea03c4df976c781a1 (patch) | |
tree | b3ae7a8203f2d4ec99a84762ea9aedda56864d88 /src/couchdb/couch_httpd_show.erl | |
parent | daa9d65a53dedaac5aeeb6394d4c0b6f99fa930c (diff) |
refactor main.js into many files and improve show/list error handling
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@766383 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_httpd_show.erl')
-rw-r--r-- | src/couchdb/couch_httpd_show.erl | 83 |
1 files changed, 48 insertions, 35 deletions
diff --git a/src/couchdb/couch_httpd_show.erl b/src/couchdb/couch_httpd_show.erl index 5aed8971..21611262 100644 --- a/src/couchdb/couch_httpd_show.erl +++ b/src/couchdb/couch_httpd_show.erl @@ -19,7 +19,7 @@ -import(couch_httpd, [send_json/2,send_json/3,send_json/4,send_method_not_allowed/2, - start_json_response/2,send_chunk/2, + start_json_response/2,send_chunk/2,send_chunked_error/2, start_chunked_response/3, send_error/4]). handle_doc_show_req(#httpd{ @@ -132,24 +132,30 @@ make_map_start_resp_fun(QueryServer, Req, Db, CurrentEtag) -> make_map_send_row_fun(QueryServer, Req) -> fun(Resp, Db2, {{Key, DocId}, Value}, RowFront, _IncludeDocs) -> - JsonResp = couch_query_servers:render_list_row(QueryServer, - Req, Db2, {{Key, DocId}, Value}), - #extern_resp_args{ - stop = StopIter, - data = RowBody - } = couch_httpd_external:parse_external_response(JsonResp), - case StopIter of - true -> stop; - _ -> - RowFront2 = case RowFront of - nil -> []; - _ -> RowFront - end, - Chunk = RowFront2 ++ binary_to_list(RowBody), - case Chunk of - [] -> {ok, Resp}; - _ -> send_chunk(Resp, Chunk) + try + JsonResp = couch_query_servers:render_list_row(QueryServer, + Req, Db2, {{Key, DocId}, Value}), + #extern_resp_args{ + stop = StopIter, + data = RowBody + } = couch_httpd_external:parse_external_response(JsonResp), + case StopIter of + true -> stop; + _ -> + RowFront2 = case RowFront of + nil -> []; + _ -> RowFront + end, + Chunk = RowFront2 ++ binary_to_list(RowBody), + case Chunk of + [] -> {ok, Resp}; + _ -> send_chunk(Resp, Chunk) + end end + catch + throw:Error -> + send_chunked_error(Resp, Error), + throw({already_sent, Resp, Error}) end end. @@ -241,24 +247,30 @@ make_reduce_start_resp_fun(QueryServer, Req, Db, CurrentEtag) -> make_reduce_send_row_fun(QueryServer, Req, Db) -> fun(Resp, {Key, Value}, RowFront) -> - JsonResp = couch_query_servers:render_reduce_row(QueryServer, - Req, Db, {Key, Value}), - #extern_resp_args{ - stop = StopIter, - data = RowBody - } = couch_httpd_external:parse_external_response(JsonResp), - RowFront2 = case RowFront of - nil -> []; - _ -> RowFront - end, - case StopIter of - true -> stop; - _ -> - Chunk = RowFront2 ++ binary_to_list(RowBody), - case Chunk of - [] -> {ok, Resp}; - _ -> send_chunk(Resp, Chunk) + try + JsonResp = couch_query_servers:render_reduce_row(QueryServer, + Req, Db, {Key, Value}), + #extern_resp_args{ + stop = StopIter, + data = RowBody + } = couch_httpd_external:parse_external_response(JsonResp), + RowFront2 = case RowFront of + nil -> []; + _ -> RowFront + end, + case StopIter of + true -> stop; + _ -> + Chunk = RowFront2 ++ binary_to_list(RowBody), + case Chunk of + [] -> {ok, Resp}; + _ -> send_chunk(Resp, Chunk) + end end + catch + throw:Error -> + send_chunked_error(Resp, Error), + throw({already_sent, Resp, Error}) end end. @@ -417,3 +429,4 @@ apply_etag({ExternalResponse}, CurrentEtag) -> Field end || Field <- ExternalResponse]} end. +
\ No newline at end of file |