handle http errors in API calls