Browse Source

@uppy/transloadit: simplify `#onTusError` (#3419)

And fixes few ESLint warnings
Antoine du Hamel 3 years ago
parent
commit
fdb3c5e51d
1 changed files with 5 additions and 5 deletions
  1. 5 5
      packages/@uppy/transloadit/src/index.js

+ 5 - 5
packages/@uppy/transloadit/src/index.js

@@ -19,6 +19,7 @@ function defaultGetAssemblyOptions (file, options) {
 const sendErrorToConsole = originalErr => err => {
   const error = new Error('Failed to send error to the client')
   error.cause = err
+  // eslint-ignore-next-line no-console
   console.error(error, originalErr)
 }
 
@@ -242,7 +243,7 @@ module.exports = class Transloadit extends BasePlugin {
     })
 
     watcher.on('assembly-error', (id, error) => {
-    // Clear postprocessing state for all our files.
+      // Clear postprocessing state for all our files.
       const files = this.getAssemblyFiles(id)
       files.forEach((file) => {
       // TODO Maybe make a postprocess-error event here?
@@ -708,10 +709,9 @@ module.exports = class Transloadit extends BasePlugin {
   }
 
   #onTusError = (err) => {
-    if (err && /^tus: /.test(err.message)) {
-      const xhr = err.originalRequest ? err.originalRequest.getUnderlyingObject() : null
-      const url = xhr && xhr.responseURL ? xhr.responseURL : null
-      this.client.submitError(err, { url, type: 'TUS_ERROR' })
+    if (err?.message?.startsWith('tus: ')) {
+      const endpoint = err.originalRequest?.getUnderlyingObject()?.responseURL
+      this.client.submitError(err, { endpoint, type: 'TUS_ERROR' })
         // if we can't report the error that sucks
         .catch(sendErrorToConsole(err))
     }