anchor.diff:              send_error(HttpReq, Error);
           error:database_does_not_exist ->
               send_error(HttpReq, database_does_not_exist);
  -        error:badarg ->
  -            ?LOG_ERROR("Badarg error in HTTP request",[]),
  -            ?LOG_INFO("Stacktrace: ~p",[erlang:get_stacktrace()]),
  -            send_error(HttpReq, badarg);
  -        error:function_clause ->
  -            ?LOG_ERROR("function_clause error in HTTP request",[]),
  -            ?LOG_INFO("Stacktrace: ~p",[erlang:get_stacktrace()]),
  -            send_error(HttpReq, function_clause);
           Tag:Error ->
               ?LOG_ERROR("Uncaught error in HTTP request: ~p",[{Tag, Error}]),
  -            ?LOG_INFO("Stacktrace: ~p",[erlang:get_stacktrace()]),
  -            send_error(HttpReq, Error)
  +            Stack = erlang:get_stacktrace(),
  +            ?LOG_INFO("Stacktrace: ~p",[Stack]),
  +            send_error(HttpReq, {Error, nil, Stack})
       end,
   
       RequestTime = timer:now_diff(now(), Begin)/1000,
  
positive.code:     true ->
          []
      end,
      send_error(Req, Code, Headers, ErrorStr, ReasonStr).
  
  send_error(Req, Code, ErrorStr, ReasonStr) ->
      send_error(Req, Code, [], ErrorStr, ReasonStr).
  
  send_error(Req, Code, Headers, ErrorStr, ReasonStr) ->
      send_json(Req, Code, Headers,
          {[{<<"error">>,  ErrorStr},
           {<<"reason">>, ReasonStr}]}).
  
  % give the option for list functions to output html or other raw errors
  send_chunked_error(Resp, {_Error, {[{<<"body">>, Reason}]}}) ->
  
negative.code: 
  reqid() ->
      {"X-Couch-Request-ID", get(nonce)}.
  
  json_stack({_Error, _Reason, Stack}) ->
      lists:map(fun({M,F,A0}) ->
          A = if is_integer(A0) -> A0; is_list(A0) -> length(A0); true -> 0 end,
          list_to_binary(io_lib:format("~s:~s/~B", [M,F,A]));
      (_) ->
          <<"bad entry in stacktrace">>
      end, Stack);
  json_stack(_) ->
      [].
  