Просмотр исходного кода

s3/multipart: Catch synchronous errors in option callbacks.

Renée Kooi 7 лет назад
Родитель
Сommit
58863f6a89
1 измененных файлов с 11 добавлено и 7 удалено
  1. 11 7
      src/plugins/AwsS3/MultipartUploader.js

+ 11 - 7
src/plugins/AwsS3/MultipartUploader.js

@@ -51,7 +51,9 @@ class MultipartUploader {
   }
   }
 
 
   _createUpload () {
   _createUpload () {
-    return this.options.createMultipartUpload().then((result) => {
+    return Promise.resolve().then(() =>
+      this.options.createMultipartUpload()
+    ).then((result) => {
       const valid = typeof result === 'object' && result &&
       const valid = typeof result === 'object' && result &&
         typeof result.uploadId === 'string' &&
         typeof result.uploadId === 'string' &&
         typeof result.key === 'string'
         typeof result.key === 'string'
@@ -72,10 +74,12 @@ class MultipartUploader {
   }
   }
 
 
   _resumeUpload () {
   _resumeUpload () {
-    this.options.listParts({
-      uploadId: this.uploadId,
-      key: this.key
-    }).then((parts) => {
+    return Promise.resolve().then(() =>
+      this.options.listParts({
+        uploadId: this.uploadId,
+        key: this.key
+      })
+    ).then((parts) => {
       parts.forEach((part) => {
       parts.forEach((part) => {
         const i = part.PartNumber - 1
         const i = part.PartNumber - 1
         this.chunkState[i] = {
         this.chunkState[i] = {
@@ -130,7 +134,7 @@ class MultipartUploader {
     const body = this.chunks[index]
     const body = this.chunks[index]
     this.chunkState[index].busy = true
     this.chunkState[index].busy = true
 
 
-    return Promise.resolve(
+    return Promise.resolve().then(() =>
       this.options.prepareUploadPart({
       this.options.prepareUploadPart({
         key: this.key,
         key: this.key,
         uploadId: this.uploadId,
         uploadId: this.uploadId,
@@ -227,7 +231,7 @@ class MultipartUploader {
     // Parts may not have completed uploading in sorted order, if limit > 1.
     // Parts may not have completed uploading in sorted order, if limit > 1.
     this.parts.sort((a, b) => a.PartNumber - b.PartNumber)
     this.parts.sort((a, b) => a.PartNumber - b.PartNumber)
 
 
-    return Promise.resolve(
+    return Promise.resolve().then(() =>
       this.options.completeMultipartUpload({
       this.options.completeMultipartUpload({
         key: this.key,
         key: this.key,
         uploadId: this.uploadId,
         uploadId: this.uploadId,