Add error handling for API queries