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 { try {
return JSON.parse(text); return JSON.parse(text);
} catch(e) { } 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) { exports["application/json"] = function(text,fields) {
var incoming, var results = [],
results = []; incoming = $tw.utils.parseJSONSafe(text,function(err) {
incoming = $tw.utils.parseJSONSafe(text,[{ return [{
title: "JSON error: " + e, title: "JSON error: " + err,
text: "" text: ""
}]); }];
});
if(!$tw.utils.isArray(incoming)) { if(!$tw.utils.isArray(incoming)) {
incoming = [incoming]; incoming = [incoming];
} }