From 57402cca8b423d06b977d23b2f79c2ca6ff0a45d Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Tue, 11 Jul 2017 11:53:38 -0400 Subject: [PATCH] catch migration error --- server/migrations/s3UnderUser.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/server/migrations/s3UnderUser.js b/server/migrations/s3UnderUser.js index d56bd205..289d212e 100644 --- a/server/migrations/s3UnderUser.js +++ b/server/migrations/s3UnderUser.js @@ -30,7 +30,6 @@ Project.find({}, (err, projects) => { const userId = project.user.valueOf(); project.files.forEach((file, fileIndex) => { if (file.url && file.url.includes(process.env.S3_BUCKET) && !file.url.includes(userId)) { - console.log(file.url); const key = file.url.split('/').pop(); console.log(key); const params = { @@ -38,16 +37,20 @@ Project.find({}, (err, projects) => { CopySource: `${process.env.S3_BUCKET}/${key}`, Key: `${userId}/${key}` }; - client.moveObject(params) - .on('err', (err) => { - console.log(err); - }) - .on('end', () => { - file.url = `https://s3-${process.env.AWS_REGION}.amazonaws.com/${process.env.S3_BUCKET}/${userId}/${key}`; - project.save((err, savedProject) => { - console.log(`updated file ${key}`); + try { + client.moveObject(params) + .on('err', (err) => { + console.log(err); + }) + .on('end', () => { + file.url = `https://s3-${process.env.AWS_REGION}.amazonaws.com/${process.env.S3_BUCKET}/${userId}/${key}`; + project.save((err, savedProject) => { + console.log(`updated file ${key}`); + }); }); - }); + } catch(e) { + console.log(e); + } } }); });