add error handling for api calls