Improved exception handling on API calls