Improve error handling and fix API's endpoint URL.