Return 404 when requesting a document that does not exist.

When requesting a document that does not exist, a 404 error should be returned, but the server was returning a 500.

I also added tests for the get_db code, and fixed an error with the doc_count return value.