Handle API error with rejected promise

Had some problems with accessing the API using potentially invalid keys, and this seemed to fix it.