Skip to content

Commit 9e22b5f

Browse files
author
Ray Schamp
committed
fix: attempt to parse all string responses as JSON
1 parent 3e91a94 commit 9e22b5f

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/WebHelper.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,17 @@ class WebHelper extends Helper {
161161
if (err || Math.floor(resp.statusCode / 100) !== 2) {
162162
return reject(err || resp.statusCode);
163163
}
164+
// xhr makes it difficult to both send FormData and automatically
165+
// parse a JSON response. So try to parse everything as JSON.
166+
if (typeof body === 'string') {
167+
try {
168+
body = JSON.parse(body);
169+
} catch (parseError) {
170+
// If it's not parseable, then we can't add the id even
171+
// if we want to, so stop here
172+
return resolve(body);
173+
}
174+
}
164175
return resolve(Object.assign({
165176
id: body['content-name'] || assetId
166177
}, body));

0 commit comments

Comments
 (0)