mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-27 09:35:56 -05:00
Merge pull request #661 from rschamp/bugfix/654
Fix JSON response parsing in IE
This commit is contained in:
commit
11155c429e
1 changed files with 10 additions and 0 deletions
|
@ -54,6 +54,16 @@ module.exports = function (opts, callback) {
|
||||||
}
|
}
|
||||||
xhr(opts, function (err, res, body) {
|
xhr(opts, function (err, res, body) {
|
||||||
if (err) log.error(err);
|
if (err) log.error(err);
|
||||||
|
if (opts.responseType === 'json' && typeof body === 'string') {
|
||||||
|
// IE doesn't parse responses as JSON without the json attribute,
|
||||||
|
// even with responseType: 'json'.
|
||||||
|
// See https://github.com/Raynos/xhr/issues/123
|
||||||
|
try {
|
||||||
|
body = JSON.parse(body);
|
||||||
|
} catch (e) {
|
||||||
|
// Not parseable anyway, don't worry about it
|
||||||
|
}
|
||||||
|
}
|
||||||
// Legacy API responses come as lists, and indicate to redirect the client like
|
// Legacy API responses come as lists, and indicate to redirect the client like
|
||||||
// [{success: true, redirect: "/location/to/redirect"}]
|
// [{success: true, redirect: "/location/to/redirect"}]
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue