Return useful error messages and debug information.

The error messages returned were pretty slim, sometimes wrong, or did not return the error.  Fix these bugs and make a nicer debug interface that keeps the server code easy to read.