Revamp XHR response handling#612
Merged
Merged
Conversation
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
}
```
...
goto-bus-stop
force-pushed
the
fix/response-errors
branch
from
February 12, 2018 12:38
fe1701c to
a384521
Compare
arturi
reviewed
Feb 18, 2018
| // body: extracted response data } | ||
|
|
||
| uppy.on('upload-success', (fileID, body) => { | ||
| // do something with extracted response data |
Contributor
There was a problem hiding this comment.
file here too, instead of fileID?
Contributor
|
👍 |
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
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Basically, this: #521
This adds a
responsekey to files when the upload completed (regardless of whether it succeeded).file.responsecontains astatusand adataproperty.datais the result ofgetResponseData. One change here is thatgetResponseDatais 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.