question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistencies in XHRUpload's response handling

See original GitHub issue

Trying out Uppy, I’m facing a blocker. I don’t think Uppy forwards me the server response, which means I can’t let the user know what happened if the server rejects the uploaded file.

Here is the code I wrote:

link(scope, elem, attrs) {
    const uppy = Uppy({
        id: attrs.id,
        autoProceed: true,
    })
    .use(DragDrop, { target: `#${attrs.id}` })
    .use(XHRUpload, {
        endpoint: `${attrs.url}`,
        headers: {
            authorization: 'Basic dGVzdDp0ZXN0Cg==',
        }
    })
    .run();

    uppy.on('complete', (result) => {
        console.log('successful files:', result.successful)
        console.error('failed files:', result.failed)
    });
}

That console.error gives me one item in result.failed

{
  "source": "DragDrop",
  "id": "uppy-transfersexport120120181147csv-2493-1515754039000",
  "name": "transfers_export_12_01_2018 11_47.csv",
  "extension": "csv",
  "meta": {
    "name": "transfers_export_12_01_2018 11_47.csv",
    "type": null
  },
  "type": null,
  "data": {
    "fullPath": "/transfers_export_12_01_2018 11_47.csv"
  },
  "progress": {
    "percentage": 100,
    "bytesUploaded": 2944,
    "bytesTotal": 2944,
    "uploadComplete": false,
    "uploadStarted": 1515761105337
  },
  "size": 2493,
  "isRemote": false,
  "remote": "",
  "error": "Upload error"
}

The server answered with

{
  "timestamp": "2018-01-12T12:43:18.71",
  "status": 422,
  "error": "Unprocessable Entity",
  "path": "/api/v1/transfers/payload_upload",
  "data": "Not a zip file"
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
bertho-zerocommented, Mar 6, 2018

On my side I did not set up the server side route, so I have a 404 error but I can not get an error on my

// autoProceed: false

try {
  const uploadResult = await this.uppy.upload();
} catch ( error ) {
  console.log('Error on upload:', error.message || error);
}

I have tried this in getResponseError:

return new Error( 'Gnégnégné, ça marche pas !' );
// or
return { message: 'Gnégnégné, ça marche pas !' };
// or
return { error: 'Gnégnégné, ça marche pas !' };
// or
throw new Error( 'Gnégnégné, ça marche pas !' );

All files are in the successful key.

0reactions
kvzcommented, May 22, 2019

We think this was solved, if not, feel free to re-open!

Read more comments on GitHub >

github_iconTop Results From Across the Web

XMLHttpRequest Send() throws error despite ... - Stack Overflow
I am using XmlhttpRequest to send a POST requests on localhost and chrome developer tools console and network to verify the requests.
Read more >
XMLHttpRequest - The Modern JavaScript Tutorial
We can upload/download files, track progress and much more. ... This will be called after the response is received xhr.onload = function() ...
Read more >
XMLHttpRequest Standard
To handle response end-of-body for an XMLHttpRequest object xhr , run these steps: Handle errors for xhr . If xhr 's response is...
Read more >
XMLHttpRequest.status - Web APIs - MDN Web Docs
The read-only XMLHttpRequest.status property returns the numerical HTTP status code of the XMLHttpRequest 's response.
Read more >
XMLHttpRequest vs the Fetch API for Ajax - SitePoint
fetch( 'http://domain/service', { method: 'GET' } ) .then( response => response.json() ) ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found