add error handling for failed API calls