anchor.diff:  send_error(Req, Code, ErrorStr, ReasonStr) ->
       send_error(Req, Code, [], ErrorStr, ReasonStr, []).
   
  -send_error(Req, Code, Headers, ErrorStr, ReasonStr, Stack) ->
  +send_error(Req, Code, Headers, ErrorStr, ReasonStr, []) ->
       send_json(Req, Code, Headers,
           {[{<<"error">>,  ErrorStr},
  -        {<<"reason">>, ReasonStr} |
  -        case Stack of [] -> []; _ -> [{stack, Stack}] end
  +        {<<"reason">>, ReasonStr}]});
  +send_error(Req, Code, Headers, ErrorStr, ReasonStr, Stack) ->
  +    log_stack_trace(Stack),
  +    send_json(Req, Code, [stack_trace_id(Stack) | Headers],
  +        {[{<<"error">>,  ErrorStr},
  +        {<<"reason">>, ReasonStr},
  +        {<<"ref">>, stack_hash(Stack)}
       ]}).
   
   % give the option for list functions to output html or other raw errors
  
positive.code:                 {exit, normal, [{mochiweb_request, send, _} | _]} ->
                      exit(normal); % Client disconnect (R14)
                  _Else ->
                      JsonStack = json_stack({Error, nil, Stack}),
                      couch_log:error("req_err ~p:~p ~p", [Tag, Error, JsonStack]),
                      send_error(HttpReq, {Error, nil, Stack})
              end
      end,
  
negative.code:     Else ->
          throw({bad_ctype, [Else, " is not a supported content encoding."]})
      end.
  
  log_stack_trace(Stack) ->
      couch_log:error("~p failed with trace: ~p", [stack_hash(Stack), Stack]).
  
  stack_trace_id(Stack) ->
      {"X-Cloudant-Stack-Hash", stack_hash(Stack)}.
  
  stack_hash(Stack) ->
      erlang:crc32(term_to_binary(Stack)).
  