Skip to content

Commit

Permalink
example: simplify code by using built-in throwIfAborted (#4749)
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 authored Oct 20, 2023
1 parent c72e411 commit c66c828
Showing 1 changed file with 4 additions and 52 deletions.
56 changes: 4 additions & 52 deletions examples/aws-nodejs/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,7 @@ <h1>AWS upload example</h1>
// 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 = {}

Expand Down Expand Up @@ -191,19 +179,7 @@ <h1>AWS upload example</h1>

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(
Expand All @@ -226,19 +202,7 @@ <h1>AWS upload example</h1>
},

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(
Expand All @@ -259,19 +223,7 @@ <h1>AWS upload example</h1>
{ 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)
Expand Down

0 comments on commit c66c828

Please sign in to comment.