Better error handling during API calls