Skip to content

Revamp XHR response handling#612

Merged
arturi merged 3 commits into
masterfrom
fix/response-errors
Feb 18, 2018
Merged

Revamp XHR response handling#612
arturi merged 3 commits into
masterfrom
fix/response-errors

Conversation

@goto-bus-stop

Copy link
Copy Markdown
Contributor

Basically, this: #521

This adds a response key to files when the upload completed (regardless of whether it succeeded). file.response contains a status and a data property. data is the result of getResponseData. One change here is that getResponseData is also called if there was an error, not sure if that's a good idea.

Also changing events to emit file objects instead of IDs here because it touches many of the same places.

When returning a string from `getResponseError`, it will be wrapped in
an Error instance.

When returning a falsy value from `getResponseError`, a default Error
message is used.

When returning something completely different, an Error instance is
created and its `.data` property will equal the return value.

Errors now include a `.request` property, whether they were caused by
the request failing entirely ('error' event) or the backend rejecting
it (during the 'load' event). Previously this only happened in the
second case.

Ref #521 (comment)
 - Make XHR responses available on the file object:

   ```js
   file.response === {
     status, // HTTP status code
     data, // response data (always available)
     error?, // if status is not 2xx
     uploadURL? // if response has an URL at which the file is now available
   }
   ```

...
// body: extracted response data }

uppy.on('upload-success', (fileID, body) => {
// do something with extracted response data

@arturi arturi Feb 18, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

file here too, instead of fileID?

@arturi

arturi commented Feb 18, 2018

Copy link
Copy Markdown
Contributor

👍

@arturi
arturi merged commit 127e54e into master Feb 18, 2018
@arturi
arturi deleted the fix/response-errors branch February 18, 2018 03:03
@arturi

arturi commented Feb 18, 2018

Copy link
Copy Markdown
Contributor

Thank you for this!

arturi added a commit that referenced this pull request Feb 18, 2018
//cc @goto-bus-stop

should we change all progress events to file instead of fileId too?

#638 might be releavant too
arturi added a commit that referenced this pull request Feb 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants