summaryrefslogtreecommitdiff
path: root/src/couchdb/couch_httpd.erl
diff options
context:
space:
mode:
authorJohn Christopher Anderson <jchris@apache.org>2009-04-17 00:47:50 +0000
committerJohn Christopher Anderson <jchris@apache.org>2009-04-17 00:47:50 +0000
commitc0171495ea1cd8b552ae39a23ad584eec5190860 (patch)
tree4ee79f4744bd1edda0215521977ce9151d8f2ec7 /src/couchdb/couch_httpd.erl
parent47edd9d102446e0b0b661d7cc4a7b46eae6a9a5e (diff)
output errors differently during chunked responses (view and list)
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@765819 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_httpd.erl')
-rw-r--r--src/couchdb/couch_httpd.erl22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl
index 1e0bd9d4..a16f5fdd 100644
--- a/src/couchdb/couch_httpd.erl
+++ b/src/couchdb/couch_httpd.erl
@@ -21,7 +21,7 @@
-export([primary_header_value/2,partition/1,serve_file/3]).
-export([start_chunked_response/3,send_chunk/2]).
-export([start_json_response/2, start_json_response/3, end_json_response/1]).
--export([send_response/4,send_method_not_allowed/2,send_error/4, send_redirect/2]).
+-export([send_response/4,send_method_not_allowed/2,send_error/4, send_redirect/2,send_chunked_error/2]).
-export([send_json/2,send_json/3,send_json/4]).
-export([default_authentication_handler/1,special_test_authentication_handler/1]).
-export([null_authentication_handler/1]).
@@ -422,6 +422,9 @@ error_info({Error, Reason}) ->
error_info(Error) ->
{500, <<"unknown_error">>, couch_util:to_binary(Error)}.
+send_error(_Req, {already_sent, _Error}) ->
+ ok;
+
send_error(Req, Error) ->
{Code, ErrorStr, ReasonStr} = error_info(Error),
if Code == 401 ->
@@ -444,6 +447,23 @@ send_error(Req, Code, Headers, ErrorStr, ReasonStr) ->
{[{<<"error">>, ErrorStr},
{<<"reason">>, ReasonStr}]}).
+send_chunked_error(Resp, Error) ->
+ {Code, ErrorStr, ReasonStr} = error_info(Error),
+ CType = Resp:get_header_value("Content-Type"),
+ case CType of
+ "text/html" ->
+ HtmlError = ?l2b([$\n,
+ "<html><body><h2>Error: ", ErrorStr, "</h2>",
+ "<pre>Reason: ", ReasonStr, "</pre>", $\n]),
+ send_chunk(Resp, HtmlError);
+ _Else ->
+ JsonError = {[{<<"code">>, Code},
+ {<<"error">>, ErrorStr},
+ {<<"reason">>, ReasonStr}]},
+ send_chunk(Resp, ?l2b([$\n,?JSON_ENCODE(JsonError),$\n]))
+ end,
+ send_chunk(Resp, []).
+
send_redirect(Req, Path) ->
Headers = [{"Location", couch_httpd:absolute_uri(Req, Path)}],
send_response(Req, 301, Headers, <<>>).