Skip to content

Commit d2db3ad

Browse files
authored
@uppy/xhr-upload: fix when responseType is set to JSON (#5651)
1 parent dd8b914 commit d2db3ad

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

packages/@uppy/xhr-upload/src/index.ts

+12-7
Original file line numberDiff line numberDiff line change
@@ -235,13 +235,18 @@ export default class XHRUpload<
235235
})
236236

237237
let body = await this.opts.getResponseData?.(res)
238-
try {
239-
body ??= JSON.parse(res.responseText) as B
240-
} catch (cause) {
241-
throw new Error(
242-
'@uppy/xhr-upload expects a JSON response (with a `url` property). To parse non-JSON responses, use `getResponseData` to turn your response into JSON.',
243-
{ cause },
244-
)
238+
239+
if (res.responseType === 'json') {
240+
body ??= res.response
241+
} else {
242+
try {
243+
body ??= JSON.parse(res.responseText) as B
244+
} catch (cause) {
245+
throw new Error(
246+
'@uppy/xhr-upload expects a JSON response (with a `url` property). To parse non-JSON responses, use `getResponseData` to turn your response into JSON.',
247+
{ cause },
248+
)
249+
}
245250
}
246251

247252
const uploadURL = typeof body?.url === 'string' ? body.url : undefined

0 commit comments

Comments
 (0)