From c66c8284f5dd2e82662513793b55e73ec1e86a30 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Fri, 20 Oct 2023 14:35:43 +0200 Subject: [PATCH] example: simplify code by using built-in `throwIfAborted` (#4749) --- examples/aws-nodejs/public/index.html | 56 ++------------------------- 1 file changed, 4 insertions(+), 52 deletions(-) diff --git a/examples/aws-nodejs/public/index.html b/examples/aws-nodejs/public/index.html index 2a5fe2b351..229d56c0e1 100644 --- a/examples/aws-nodejs/public/index.html +++ b/examples/aws-nodejs/public/index.html @@ -121,19 +121,7 @@

AWS upload example

// 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 @@

AWS upload example

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 @@

AWS upload example

}, 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 @@

AWS upload example

{ 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)