httpd: log bugs with stacktrace

Log a stack-trace and return appropriate HTTP response status code if
a bug is detected.

Target: master