Sfoglia il codice sorgente

example: simplify code by using built-in `throwIfAborted` (#4749)

Antoine du Hamel 1 anno fa
parent
commit
c66c8284f5
1 ha cambiato i file con 4 aggiunte e 52 eliminazioni
  1. 4 52
      examples/aws-nodejs/public/index.html

+ 4 - 52
examples/aws-nodejs/public/index.html

@@ -121,19 +121,7 @@
             // implement them (you'd also need to set `shouldUseMultipart: false` though).
 
             async createMultipartUpload(file, signal) {
-              if (signal?.aborted) {
-                const err = new DOMException(
-                  'The operation was aborted',
-                  'AbortError',
-                )
-                Object.defineProperty(err, 'cause', {
-                  __proto__: null,
-                  configurable: true,
-                  writable: true,
-                  value: signal.reason,
-                })
-                throw err
-              }
+              signal?.throwIfAborted()
 
               const metadata = {}
 
@@ -191,19 +179,7 @@
 
               const { uploadId, key, partNumber, signal } = options
 
-              if (signal?.aborted) {
-                const err = new DOMException(
-                  'The operation was aborted',
-                  'AbortError',
-                )
-                Object.defineProperty(err, 'cause', {
-                  __proto__: null,
-                  configurable: true,
-                  writable: true,
-                  value: signal.reason,
-                })
-                throw err
-              }
+              signal?.throwIfAborted()
 
               if (uploadId == null || key == null || partNumber == null) {
                 throw new Error(
@@ -226,19 +202,7 @@
             },
 
             async listParts(file, { key, uploadId }, signal) {
-              if (signal?.aborted) {
-                const err = new DOMException(
-                  'The operation was aborted',
-                  'AbortError',
-                )
-                Object.defineProperty(err, 'cause', {
-                  __proto__: null,
-                  configurable: true,
-                  writable: true,
-                  value: signal.reason,
-                })
-                throw err
-              }
+              signal?.throwIfAborted()
 
               const filename = encodeURIComponent(key)
               const response = await fetch(
@@ -259,19 +223,7 @@
               { key, uploadId, parts },
               signal,
             ) {
-              if (signal?.aborted) {
-                const err = new DOMException(
-                  'The operation was aborted',
-                  'AbortError',
-                )
-                Object.defineProperty(err, 'cause', {
-                  __proto__: null,
-                  configurable: true,
-                  writable: true,
-                  value: signal.reason,
-                })
-                throw err
-              }
+              signal?.throwIfAborted()
 
               const filename = encodeURIComponent(key)
               const uploadIdEnc = encodeURIComponent(uploadId)