Skip to content

Commit

Permalink
@uppy/tus: wait for user promise on beforeRequest (#3712)
Browse files Browse the repository at this point in the history
Fixes: #3710
Co-authored-by: Merlijn Vos <[email protected]>
  • Loading branch information
aduh95 and Murderlon authored May 17, 2022
1 parent 7d7c4dd commit 77aacf1
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions packages/@uppy/tus/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,9 @@ export default class Tus extends BasePlugin {
const xhr = req.getUnderlyingObject()
xhr.withCredentials = !!opts.withCredentials

let userProvidedPromise
if (typeof opts.onBeforeRequest === 'function') {
opts.onBeforeRequest(req)
userProvidedPromise = opts.onBeforeRequest(req)
}

if (hasProperty(queuedRequest, 'shouldBeRequeued')) {
Expand All @@ -229,9 +230,17 @@ export default class Tus extends BasePlugin {
done()
return () => {}
})
return p
// If the request has been requeued because it was rate limited by the
// remote server, we want to wait for `RateLimitedQueue` to dispatch
// the re-try request.
// Therefore we create a promise that the queue will resolve when
// enough time has elapsed to expect not to be rate-limited again.
// This means we can hold the Tus retry here with a `Promise.all`,
// together with the returned value of the user provided
// `onBeforeRequest` option callback (in case it returns a promise).
return Promise.all([p, userProvidedPromise])
}
return undefined
return userProvidedPromise
}

uploadOptions.onError = (err) => {
Expand Down

0 comments on commit 77aacf1

Please sign in to comment.