Improve API error handling.