This commit is contained in:
jeremy@jermolene.com 2022-01-15 13:13:11 +00:00
parent 42768ca166
commit 8f4e15666a
2 changed files with 12 additions and 7 deletions

View File

@ -414,7 +414,11 @@ $tw.utils.parseJSONSafe = function(text,defaultJSON) {
try {
return JSON.parse(text);
} catch(e) {
return defaultJSON || {};
if(typeof defaultJSON === "function") {
return defaultJSON(e);
} else {
return defaultJSON || {};
}
}
};

View File

@ -17,12 +17,13 @@ exports["application/x-tiddler-html-div"] = function(text,fields) {
};
exports["application/json"] = function(text,fields) {
var incoming,
results = [];
incoming = $tw.utils.parseJSONSafe(text,[{
title: "JSON error: " + e,
text: ""
}]);
var results = [],
incoming = $tw.utils.parseJSONSafe(text,function(err) {
return [{
title: "JSON error: " + err,
text: ""
}];
});
if(!$tw.utils.isArray(incoming)) {
incoming = [incoming];
}