Improved error handling when upgrading content.
parent
a38a0f1253
commit
2011e856c0
|
@ -211,19 +211,28 @@ var H5PUpgrades = H5PUpgrades || {};
|
||||||
|
|
||||||
var current = 0; // Track progress
|
var current = 0; // Track progress
|
||||||
asyncSerial(parameters, function (id, params, next) {
|
asyncSerial(parameters, function (id, params, next) {
|
||||||
|
try {
|
||||||
// Make params possible to work with
|
// Make params possible to work with
|
||||||
params = JSON.parse(params);
|
params = JSON.parse(params);
|
||||||
|
if (!(params instanceof Object)) {
|
||||||
|
throw true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (event) {
|
||||||
|
return next(info.errorContent.replace('%id', id) + ' ' + info.errorParamsBroken);
|
||||||
|
}
|
||||||
|
|
||||||
// Upgrade this content.
|
// Upgrade this content.
|
||||||
self.upgrade(info.library.name, new Version(info.library.version), self.version, params, function (err, params) {
|
self.upgrade(info.library.name, new Version(info.library.version), self.version, params, function (err, params) {
|
||||||
if (!err) {
|
if (err) {
|
||||||
upgraded[id] = JSON.stringify(params);
|
return next(info.errorContent.replace('%id', id) + ' ' + err);
|
||||||
|
|
||||||
current++;
|
|
||||||
self.throbber.setProgress(Math.round((info.total - self.left + current) / (info.total / 100)) + ' %');
|
|
||||||
}
|
}
|
||||||
next(err);
|
|
||||||
|
upgraded[id] = JSON.stringify(params);
|
||||||
|
|
||||||
|
current++;
|
||||||
|
self.throbber.setProgress(Math.round((info.total - self.left + current) / (info.total / 100)) + ' %');
|
||||||
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
}, function (err) {
|
}, function (err) {
|
||||||
|
@ -374,14 +383,16 @@ var H5PUpgrades = H5PUpgrades || {};
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// We found an upgrade hook, run it
|
// We found an upgrade hook, run it
|
||||||
if (upgrade.contentUpgrade !== undefined && typeof upgrade.contentUpgrade === 'function') {
|
var unnecessaryWrapper = (upgrade.contentUpgrade !== undefined ? upgrade.contentUpgrade : upgrade);
|
||||||
upgrade.contentUpgrade(params, function (err, upgradedParams) {
|
|
||||||
|
try {
|
||||||
|
unnecessaryWrapper(params, function (err, upgradedParams) {
|
||||||
params = upgradedParams;
|
params = upgradedParams;
|
||||||
nextMinor(err);
|
nextMinor(err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
catch (err) {
|
||||||
nextMinor(info.errorScript.replace('%lib', library.name + ' ' + newVersion));
|
next(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, nextMajor);
|
}, nextMajor);
|
||||||
|
|
Loading…
Reference in New Issue