Improved API errors handling