Improve json error handling so the stack trace is redirected to the log
file and a pretty error message is printed.