transloadit/uppy

Duplicate error emitted when receiving an error from the TUS server.

Closed this issue · 3 comments

Initial checklist

  • I understand this is a bug report and questions should be posted in the Community Forum
  • I searched issues and couldn’t find anything (or linked relevant results below)

Link to runnable example

https://stackblitz.com/edit/vitejs-vite-4rtdaq?file=main.js

Steps to reproduce

Upload a file and let the server return an error response. You will see same error logged twice in the console view upload-error emitted event.

Expected behavior

Error to be logged and emitted only once.

Actual behavior

Error logged and emitted twice.

See https://community.transloadit.com/t/uppy-tus-is-reporting-the-same-error-twice/17272/6 for more detailed report.

Copying @amanagr original findings from the community forum over here:

Once here - link to uppy code:

uploadOptions.onError = (err) => {
        this.uppy.log(err)

        const xhr =
          (err as tus.DetailedError).originalRequest != null ?
            (err as tus.DetailedError).originalRequest.getUnderlyingObject()
          : null
        if (isNetworkError(xhr)) {
          // eslint-disable-next-line no-param-reassign
          err = new NetworkError(err, xhr)
        }

        this.resetUploaderReferences(file.id)
        queuedRequest?.abort()

        this.uppy.emit('upload-error', file, err)
        if (typeof opts.onError === 'function') {
          opts.onError(err)
        }
        reject(err)
      }

and once here - link to uppy code:

    }).catch((err) => {
      this.uppy.emit('upload-error', file, err)
      throw err
    })

From briefly looking at the linked code, I agree that is looks like we can get rid of this.uppy.emit('upload-error', file, err) in onError.

Opened #5485 for this.