Skip to content

Commit e2c6259

Browse files
authored
@uppy/transloadit: ignore rate limiting errors when polling (#3418)
Fixes: #3156
1 parent a08ec4e commit e2c6259

File tree

1 file changed

+30
-20
lines changed

1 file changed

+30
-20
lines changed

packages/@uppy/transloadit/src/Assembly.js

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,6 @@ class TransloaditAssembly extends Emitter {
7979
this.emit('connect')
8080
})
8181

82-
socket.on('connect_failed', () => {
83-
this.#onError(new NetworkError('Transloadit Socket.io connection error'))
84-
this.socket = null
85-
})
86-
8782
socket.on('connect_error', () => {
8883
socket.disconnect()
8984
this.socket = null
@@ -126,6 +121,7 @@ class TransloaditAssembly extends Emitter {
126121

127122
#onError (err) {
128123
this.emit('error', Object.assign(new Error(err.message), err))
124+
this.close()
129125
}
130126

131127
/**
@@ -148,21 +144,35 @@ class TransloaditAssembly extends Emitter {
148144
* Pass `diff: false` to avoid emitting diff events, instead only emitting
149145
* 'status'.
150146
*/
151-
#fetchStatus ({ diff = true } = {}) {
152-
return fetchWithNetworkError(this.status.assembly_ssl_url)
153-
.then((response) => response.json())
154-
.then((status) => {
155-
// Avoid updating if we closed during this request's lifetime.
156-
if (this.closed) return
157-
this.emit('status', status)
158-
159-
if (diff) {
160-
this.updateStatus(status)
161-
} else {
162-
this.status = status
163-
}
164-
})
165-
.catch((err) => this.#onError(err))
147+
async #fetchStatus ({ diff = true } = {}) {
148+
if (this.closed) return
149+
150+
try {
151+
const response = await fetchWithNetworkError(this.status.assembly_ssl_url)
152+
153+
if (this.closed) return
154+
155+
// In case of rate-limiting, ignore the error.
156+
if (response.status === 429) return
157+
158+
if (!response.ok) {
159+
this.#onError(new NetworkError(response.statusText))
160+
return
161+
}
162+
163+
const status = await response.json()
164+
// Avoid updating if we closed during this request's lifetime.
165+
if (this.closed) return
166+
this.emit('status', status)
167+
168+
if (diff) {
169+
this.updateStatus(status)
170+
} else {
171+
this.status = status
172+
}
173+
} catch (err) {
174+
this.#onError(err)
175+
}
166176
}
167177

168178
update () {

0 commit comments

Comments
 (0)