better error handling on APIclient