Fix init error message(s) formatting

This commit is contained in:
Oliver Hamlet
2017-01-05 20:35:02 +00:00
parent 2afaa5e8df
commit 69ccd5bbf5
2 changed files with 14 additions and 11 deletions
+13 -6
View File
@@ -131,18 +131,25 @@
function getInitErrors() {
return query('getInitErrors').then((result) => {
if (JSON.parse(result)) {
const errors = JSON.parse(result);
if (errors.length > 0) {
throw new Error(result);
}
});
}
function handleInitErrors(error) {
if (error.constructor === Array) {
dom.listInitErrors(JSON.parse(error.message));
} else {
dom.listInitErrors([error.message]);
function getErrorMessages(string) {
/* error.message could be a message string or JSON encoding a list of
message strings. */
try {
return JSON.parse(string);
} catch (error) {
return [string];
}
}
function handleInitErrors(error) {
dom.listInitErrors(getErrorMessages(error.message));
Dialog.closeProgress();
dom.openDialog('settingsDialog');
}
+1 -5
View File
@@ -35,11 +35,7 @@ public:
GetInitErrorsQuery(LootState& state) : state_(state) {}
std::string executeLogic() {
YAML::Node node(state_.getInitErrors());
if (node.size() > 0)
return JSON::stringify(node);
return "null";
return JSON::stringify(YAML::Node(state_.getInitErrors()));
}
private: