-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
On upload error response is undefined #5494
Comments
I just wrote this test to confirm it but I correctly receive the it('should send response object over upload-error event', async () => {
nock('https://fake-endpoint.uppy.io')
.defaultReplyHeaders({
'access-control-allow-method': 'POST',
'access-control-allow-origin': '*',
})
.options('/')
.reply(204, {})
.post('/')
.reply(400, { status: 400, message: 'Oh no' })
const core = new Core()
const shouldRetry = vi.fn(() => false)
core.use(XHRUpload, {
id: 'XHRUpload',
endpoint: 'https://fake-endpoint.uppy.io',
shouldRetry,
})
const id = core.addFile({
type: 'image/png',
source: 'test',
name: 'test.jpg',
data: new Blob([new Uint8Array(8192)]),
})
const event = new Promise<
Parameters<UppyEventMap<any, any>['upload-error']>
>((resolve) => {
core.once('upload-error', (...args) => resolve(args))
})
await Promise.all([
core.upload(),
event.then(([file, , response]) => {
expect(file).toEqual(core.getFile(id))
expect(response).toBeInstanceOf(XMLHttpRequest)
}),
])
expect(shouldRetry).toHaveBeenCalledTimes(1)
}) |
You can use |
hmm, I'm thinking that it is maybe related with the response object itself and the way it parses it? What if there is no "message" field in the response? |
Test still passes if I change it - .reply(400, { status: 400, message: 'Oh no' })
+ .reply(400, { random: true }) If you can find an easy way to reproduce I can look into it. Otherwise not sure what to do. |
Ok, it will take some time but I will give you some repro code once I get everything moved back to an open source project I'm working on. For now, I found an alternative by using onAfterResponse event on the XHR object. |
Initial checklist
Link to runnable example
No response
Steps to reproduce
Create a simple upload-error event handler in a Vue 3 app.
Result when trying to upload a file that already exist:
As you can see the response is undefined.
Also, here is the failed request (error 400) response:
I’m using Uppy version 4.2.1 with XHRUpload.
The goal I’m trying to reach is to be able to create my own notifications on the UI based on API failed request response.
Also, I’m trying to find a way to set the retry count to only 1 so that I get only one notification. Is it possible?
Expected behavior
response should be returned
Actual behavior
response is undefined
The text was updated successfully, but these errors were encountered: