Improved API errors handler.