improve error handling for API cli