Improved error handling for API Result class