Fix mishandling of errors in API client

In the unusual case that we don't get an error dict (that is, the API
itself messed up), we shouldn't die with an AttributeError, and raise
an APIError instead.