Add error handling to API calls