Improved API call error handling