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.