Skip to content

Commit

Permalink
Merge pull request #281 from alex-chew/fix-asset-uploader-error-logging
Browse files Browse the repository at this point in the history
Fix some asset uploader error cases
  • Loading branch information
echo-bravo-yahoo authored Jun 28, 2019
2 parents 9a4a214 + 0c0e317 commit b3a9f66
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lambdas/static-asset-uploader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ function cleanS3Bucket(bucketName) {
function createCatalogDirectory(staticBucketName) {
let params = { Bucket: staticBucketName, Key: 'catalog/', Body: '' }
return exports.s3.upload(params).promise()
.catch(err => {
console.log('Error creating "catalog" directory', err)
})
}

/**
Expand All @@ -195,11 +198,11 @@ function createCatalogDirectory(staticBucketName) {
*/
async function createSdkGenerationFile(staticBucketName) {
return await exports.s3.headObject({ Bucket: staticBucketName, Key: 'sdkGeneration.json' }).promise()
.catch((error) => {
console.error(error)
.catch(async _error => {
// assume it's a NotFound error, and upload a new version
console.log('Uploading sdkGeneration.json since it seems to not exist')
let params = { Bucket: staticBucketName, Key: 'sdkGeneration.json', Body: '{}' }
return exports.s3.upload(params).promise()
return await exports.s3.upload(params).promise()
})

}
Expand Down Expand Up @@ -255,7 +258,8 @@ function processFile(fileStat, readPromises, uploadPromises, bucketName, event,
params.ACL = "public-read"
}

uploadPromises.push(exports.s3.upload(params, options).promise())
uploadPromises.push(exports.s3.upload(params, options).promise()
.catch(err => { throw err }))
})
.catch(error => {
console.log(`Failed to upload:`, error)
Expand Down

0 comments on commit b3a9f66

Please sign in to comment.