Complete error handling for API call