added error handling for all api calls