Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@uppy/transloadit: ignore rate limiting errors when polling #3418

Merged
merged 1 commit into from
Jan 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 30 additions & 20 deletions packages/@uppy/transloadit/src/Assembly.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ class TransloaditAssembly extends Emitter {
this.emit('connect')
})

socket.on('connect_failed', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it never fires, outdated event?

this.#onError(new NetworkError('Transloadit Socket.io connection error'))
this.socket = null
})

socket.on('connect_error', () => {
socket.disconnect()
this.socket = null
Expand Down Expand Up @@ -126,6 +121,7 @@ class TransloaditAssembly extends Emitter {

#onError (err) {
this.emit('error', Object.assign(new Error(err.message), err))
this.close()
}

/**
Expand All @@ -148,21 +144,35 @@ class TransloaditAssembly extends Emitter {
* Pass `diff: false` to avoid emitting diff events, instead only emitting
* 'status'.
*/
#fetchStatus ({ diff = true } = {}) {
return fetchWithNetworkError(this.status.assembly_ssl_url)
.then((response) => response.json())
.then((status) => {
// Avoid updating if we closed during this request's lifetime.
if (this.closed) return
this.emit('status', status)

if (diff) {
this.updateStatus(status)
} else {
this.status = status
}
})
.catch((err) => this.#onError(err))
async #fetchStatus ({ diff = true } = {}) {
if (this.closed) return

try {
const response = await fetchWithNetworkError(this.status.assembly_ssl_url)

if (this.closed) return

// In case of rate-limiting, ignore the error.
if (response.status === 429) return

if (!response.ok) {
this.#onError(new NetworkError(response.statusText))
return
}

const status = await response.json()
// Avoid updating if we closed during this request's lifetime.
if (this.closed) return
this.emit('status', status)

if (diff) {
this.updateStatus(status)
} else {
this.status = status
}
} catch (err) {
this.#onError(err)
}
}

update () {
Expand Down