From b45e53483fe309041d26c5f237699c0ebfc4aef3 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Mon, 8 Jan 2018 15:01:43 -0500 Subject: [PATCH] try moving url if key does not exist --- server/migrations/s3UnderUser.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/server/migrations/s3UnderUser.js b/server/migrations/s3UnderUser.js index d7f4f4e6..0b6d69b8 100644 --- a/server/migrations/s3UnderUser.js +++ b/server/migrations/s3UnderUser.js @@ -55,10 +55,14 @@ Project.count({}).exec().then((numProjects) => { }; try { client.moveObject(params) - .on('err', (err) => { - console.log('in error event function'); - // console.log(err); - fileCb(); + .on('error', (err) => { + console.log(err); + file.url = (process.env.S3_BUCKET_URL_BASE || + `https://s3-${process.env.AWS_REGION}.amazonaws.com/${process.env.S3_BUCKET}`) + `/${userId}/${key}`; + project.save((err, savedProject) => { + console.log(`updated file ${key}`); + fileCb(); + }); }) .on('end', () => { file.url = (process.env.S3_BUCKET_URL_BASE || @@ -69,8 +73,7 @@ Project.count({}).exec().then((numProjects) => { }); }); } catch(e) { - console.log('in catch function'); - // console.log(e); + console.log(e); fileCb(); } } else {