don't try to use db connection if error is thrown

Currently, if there are issues connecting to mongo
db.migrationCollection is still called. If db is undefined, this will
raise an exception. Moving error conditional up, so that an error is
logged instead.
Merge pull request #14 from emirose/master

don't try to use db connection if error is thrown