Skip to content

Commit f19a8d9

Browse files
Make code safer
1 parent 0a05dda commit f19a8d9

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

deps/rabbitmq_management/priv/www/js/global.js

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,26 +1147,51 @@ class ApplicationListener {
11471147
}
11481148
var applicationListeners = new Map();
11491149
function registerApplicationListener(name, listener) {
1150+
if (name == null || (typeof name === 'string' && name.trim() === '')) {
1151+
return false;
1152+
}
1153+
if (listener == null || typeof listener !== 'object') {
1154+
return false;
1155+
}
11501156
if (applicationListeners.has(name)) {
11511157
return false;
11521158
}
11531159
applicationListeners.set(name, listener);
1160+
return true;
11541161
}
11551162
function unregisterApplicationListener(name) {
11561163
applicationListeners.delete(name);
11571164
}
11581165
function notifyOnRefresh() {
1159-
for (const [name, listener] of applicationListeners) {
1160-
listener.onRefresh();
1166+
for (const [_name, listener] of applicationListeners) {
1167+
if (listener && typeof listener.onRefresh === 'function') {
1168+
try {
1169+
listener.onRefresh();
1170+
} catch (err) {
1171+
console.error(`ApplicationListener failed due to ${err}`);
1172+
}
1173+
}
11611174
}
11621175
}
11631176
function notifyOnVhostChange(newVhost) {
11641177
for (const [_name, listener] of applicationListeners) {
1165-
listener.onVhostChange(newVhost);
1178+
if (listener && typeof listener.onVhostChange === 'function') {
1179+
try {
1180+
listener.onVhostChange(newVhost);
1181+
} catch (err) {
1182+
console.error(`ApplicationListener failed due to ${err}`);
1183+
}
1184+
}
11661185
}
11671186
}
11681187
function notifyActivatedTab(tab) {
11691188
for (const [_name, listener] of applicationListeners) {
1170-
listener.onTabActivated(tab);
1189+
if (listener && typeof listener.onTabActivated === 'function') {
1190+
try {
1191+
listener.onTabActivated(tab);
1192+
} catch (err) {
1193+
console.error(`ApplicationListener failed due to ${err}`);
1194+
}
1195+
}
11711196
}
11721197
}

deps/rabbitmq_management/priv/www/js/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1540,7 +1540,7 @@ function check_bad_response(req, full_page_404, on404fun) {
15401540
if ((req.status == 401 || req.status == 403) && oauth.enabled) {
15411541
initiate_logout(oauth, reason);
15421542
} else if (on404fun && (typeof on404fun === 'function') && req.status == 404) {
1543-
on404fun(JSON.parse(req.responseText));
1543+
on404fun(response);
15441544
} else {
15451545
show_popup('warn', fmt_escape_html(reason));
15461546
}

0 commit comments

Comments
 (0)