Force error catching while SNMP browsing

This commit is contained in:
fbsanchez 2021-02-09 10:25:42 +01:00
parent 40e97f6cf6
commit ecf0f3d161
2 changed files with 228 additions and 200 deletions

View File

@ -19,9 +19,23 @@ require_once $config['homedir'].'/include/functions_network_components.php';
global $config;
if (is_ajax()) {
ob_clean();
set_error_handler(
function ($code, $string, $file, $line) {
throw new ErrorException($string, null, $code, $file, $line);
}
);
register_shutdown_function(
function () {
$error = error_get_last();
if (null !== $error) {
echo $error['message'];
}
}
);
try {
if ((bool) is_ajax() === true) {
$method = (string) get_parameter('method', '');
$action = (string) get_parameter('action', '');
$target_ip = (string) get_parameter('target_ip', '');
@ -246,6 +260,10 @@ if (is_ajax()) {
];
echo json_encode($return);
}
}
} catch (\Exception $e) {
$e->getMessage();
} finally {
exit;
}
}

View File

@ -64,8 +64,18 @@ function snmpBrowse() {
// Manage click and select events.
snmp_browser_events_manage();
},
error: function(e) {
$("#snmp_browser").html(e);
error: function(XMLHttpRequest, textStatus, errorThrown) {
$("#spinner").css("display", "none");
$("#snmp_browser").html(
"<p>Status: " +
textStatus +
"</p><p>" +
"Error: " +
errorThrown +
"</p><p>" +
XMLHttpRequest.responseText +
"</p>"
);
}
});
}