This file appears to be more complicated than it needs to be. My suggestions:
- Remove
batchify()
. Perhaps, instead, use an approach like this for promises.
- Reduce nesting
- Throw errors instead of
console.error()
ing and returning like what's been done here.
- Ensure every function is used and needed.