Browse Source

v8.1.2: Enhance server status checks and exception handling logic

Improved the server status check by adding sessionStorage management and handling responses for better UI feedback. Changed some function signatures for consistency and better error handling. Updated routes and database initialization to reflect new functions and database versions.
pull/401/head
Aidaho 3 weeks ago
parent
commit
e9473088d5
  1. 2
      app/api/routes/routes.py
  2. 1
      app/create_db.py
  3. 2
      app/modules/roxywi/common.py
  4. 2
      app/routes/server/routes.py
  5. 13
      app/static/js/admin/server.js

2
app/api/routes/routes.py

@ -81,7 +81,7 @@ register_api_id_ip(CheckerView, 'checker', '/tools')
register_api_id_ip(InstallView, 'install', '/install', methods=['POST', 'PUT', 'DELETE'])
register_api_id_ip(ServiceActionView, 'service_action', '/<any(start, stop, reload, restart):action>', methods=['GET'])
register_api(ServerView, 'server', '/server', 'server_id')
register_api_for_not_api(ServerView, 'server', '/server', 'server_id')
register_api(BackupView, 'backup_fs', '/server/backup/fs', 'backup_id')
register_api(S3BackupView, 'backup_s3', '/server/backup/s3', 'backup_id')
register_api(GitBackupView, 'backup_git', '/server/backup/git', 'backup_id')

1
app/create_db.py

@ -722,4 +722,5 @@ def update_all():
update_db_v_8_1_0_1()
update_db_v_8_1_0_2()
update_db_v_8_1_0_3()
update_db_v_8_1_2()
update_ver()

2
app/modules/roxywi/common.py

@ -323,7 +323,7 @@ def handle_json_exceptions(ex: Exception, message: str, server_ip='Roxy-WI serve
return ErrorResponse(error=f'{message}: {ex}').model_dump(mode='json')
def handler_exceptions_for_json_data(ex: Exception, main_ex_mes: str) -> tuple[dict, int]:
def handler_exceptions_for_json_data(ex: Exception, main_ex_mes: str = '') -> tuple[dict, int]:
if isinstance(ex, KeyError):
return handle_json_exceptions(ex, 'Missing key in JSON data'), 500
elif isinstance(ex, ValueError):

2
app/routes/server/routes.py

@ -62,7 +62,7 @@ def check_server(server_id):
try:
server = server_sql.get_server_by_id(server_id)
except Exception as e:
raise e
return roxywi_common.handler_exceptions_for_json_data(e)
result = server_mod.server_is_up(server.ip)
status = {
"status": result,

13
app/static/js/admin/server.js

@ -341,10 +341,23 @@ function showServerInfo(id, ip) {
});
}
async function serverIsUp(server_id) {
if (sessionStorage.getItem('server-' + server_id) === '0') {
return false;
}
let server_div = $('#server_status-' + server_id);
$.ajax({
url: "/server/check/server/" + server_id,
contentType: "application/json; charset=utf-8",
statusCode: {
204: function (xhr) {
$("#server-" + server_id).remove();
sessionStorage.setItem('server-'+server_id, '0');
},
404: function (xhr) {
$("#server-" + server_id).remove();
sessionStorage.setItem('server-'+server_id, '0');
}
},
success: function (data) {
if (data.status === 'up') {
server_div.removeClass('serverNone');

Loading…
Cancel
Save