Simplify error reporting

This commit is contained in:
Nick O'Leary 2024-11-08 16:46:19 +00:00
parent a69a35aacf
commit 4ff748c1c1
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9

View File

@ -385,13 +385,11 @@ RED.palette.editor = (function() {
var catalogueCount; var catalogueCount;
var catalogueLoadStatus = []; var catalogueLoadStatus = [];
var catalogueLoadStart; var catalogueLoadStart;
var catalogueLoadErrors = false;
var activeSort = sortModulesRelevance; var activeSort = sortModulesRelevance;
function refreshCatalogues (done) { function refreshCatalogues (done) {
catalogueLoadStatus = []; catalogueLoadStatus = [];
catalogueLoadErrors = false;
catalogueCount = catalogues.length; catalogueCount = catalogues.length;
loadedList = [] loadedList = []
loadedIndex = {} loadedIndex = {}
@ -401,10 +399,9 @@ RED.palette.editor = (function() {
const url = catalogues[index]; const url = catalogues[index];
$.getJSON(url, {_: new Date().getTime()},function(v) { $.getJSON(url, {_: new Date().getTime()},function(v) {
loadedCatalogs.push({ index: index, url: url, name: v.name, updated_at: v.updated_at, modules_count: (v.modules || []).length }) loadedCatalogs.push({ index: index, url: url, name: v.name, updated_at: v.updated_at, modules_count: (v.modules || []).length })
handleCatalogResponse(null,{ url: url, name: v.name},index,v); handleCatalogResponse({ url: url, name: v.name},index,v);
}).fail(function(jqxhr, textStatus, error) { }).fail(function(jqxhr, textStatus, error) {
console.warn("Error loading catalog",url,":",error); console.warn("Error loading catalog",url,":",error);
handleCatalogResponse(jqxhr,url,index);
}).always(function() { }).always(function() {
handled++; handled++;
if (handled === catalogueCount) { if (handled === catalogueCount) {
@ -419,47 +416,31 @@ RED.palette.editor = (function() {
} }
} }
function handleCatalogResponse(err,catalog,index,v) { function handleCatalogResponse(catalog,index,v) {
const url = catalog.url if (v.modules) {
catalogueLoadStatus.push(err); v.modules = v.modules.filter(function(m) {
if (!err) { if (RED.utils.checkModuleAllowed(m.id,m.version,installAllowList,installDenyList)) {
if (v.modules) { loadedIndex[m.id] = m;
v.modules = v.modules.filter(function(m) { m.index = [m.id];
if (RED.utils.checkModuleAllowed(m.id,m.version,installAllowList,installDenyList)) { if (m.keywords) {
loadedIndex[m.id] = m; m.index = m.index.concat(m.keywords);
m.index = [m.id];
if (m.keywords) {
m.index = m.index.concat(m.keywords);
}
if (m.types) {
m.index = m.index.concat(m.types);
}
if (m.updated_at) {
m.timestamp = new Date(m.updated_at).getTime();
} else {
m.timestamp = 0;
}
m.index = m.index.join(",").toLowerCase();
m.catalog = catalog;
m.catalogIndex = index;
return true;
} }
return false; if (m.types) {
}) m.index = m.index.concat(m.types);
loadedList = loadedList.concat(v.modules); }
} if (m.updated_at) {
} else { m.timestamp = new Date(m.updated_at).getTime();
catalogueLoadErrors = true; } else {
} m.timestamp = 0;
if (catalogueLoadStatus.length === catalogueCount) { }
if (catalogueLoadErrors) { m.index = m.index.join(",").toLowerCase();
RED.notify(RED._('palette.editor.errors.catalogLoadFailed',{url: url}),"error",false,8000); m.catalog = catalog;
} m.catalogIndex = index;
var delta = 250-(Date.now() - catalogueLoadStart); return true;
setTimeout(function() { }
$("#red-ui-palette-module-install-shade").hide(); return false;
},Math.max(delta,0)); })
loadedList = loadedList.concat(v.modules);
} }
} }
@ -472,6 +453,7 @@ RED.palette.editor = (function() {
$(".red-ui-palette-module-shade-status").text(RED._('palette.editor.loading')); $(".red-ui-palette-module-shade-status").text(RED._('palette.editor.loading'));
$("#red-ui-palette-module-install-shade").show(); $("#red-ui-palette-module-install-shade").show();
catalogueLoadStart = Date.now()
refreshCatalogues(function () { refreshCatalogues(function () {
refreshNodeModuleList(); refreshNodeModuleList();
updateCatalogFilter(loadedCatalogs) updateCatalogFilter(loadedCatalogs)