Update index.js

Close on error status