API error handling enhancements