anchor.diff:          {[{<<"error">>,  ErrorStr},
           {<<"reason">>, ReasonStr}]});
   send_error(Req, Code, Headers, ErrorStr, ReasonStr, Stack) ->
  -    log_stack_trace(Stack),
  +    log_error_with_stack_trace({ErrorStr, ReasonStr, Stack}),
       send_json(Req, Code, [stack_trace_id(Stack) | Headers],
           {[{<<"error">>,  ErrorStr},
  -        {<<"reason">>, ReasonStr},
  -        {<<"ref">>, stack_hash(Stack)}
  +        {<<"reason">>, ReasonStr} |
  +        case Stack of [] -> []; _ -> [{<<"ref">>, stack_hash(Stack)}] end
       ]}).
   
   % give the option for list functions to output html or other raw errors
  
positive.code:     {ok, Resp} = send_error(Req, Code, ErrorStr, ReasonStr),
      {ok, DelayedResp#delayed_resp{resp=Resp}};
  send_delayed_error(#delayed_resp{resp=Resp}, Reason) ->
      log_stack_trace(json_stack(Reason)),
      throw({http_abort, Resp, Reason}).
  
  end_delayed_json_response(#delayed_resp{}=DelayedResp) ->
  
negative.code:         throw({bad_ctype, [Else, " is not a supported content encoding."]})
      end.
  
  log_error_with_stack_trace({bad_request, _, _}) ->
      ok;
  log_error_with_stack_trace({Error, Reason, Stack}) ->
      couch_log:error("ref: ~p req_err ~p:~p ~p",
               [stack_hash(Stack), Error, Reason, Stack]);
  log_error_with_stack_trace(_) ->
      ok.
  
  stack_trace_id(Stack) ->
      {"X-Cloudant-Stack-Hash", stack_hash(Stack)}.
  