Improves handling of API errors