Update index.js

failure instead of error + proper failedCount handling