Fix failing api middleware test.

Not sure if it's right to throw a "bad gateway" error if the server is
returning 404, though, so I'd like this reviewed. This should fix #356.
Merge pull request #357 from toolness/issue-356

Fix failing api middleware test.