mirror of
https://github.com/hubHarmony/servii-backend.git
synced 2024-11-17 21:40:31 +00:00
[+] Error handling & firebase logs
Signed-off-by: Charles Le Maux <charles.le-maux@epitech.eu>
This commit is contained in:
parent
f9534c6aa2
commit
e60e972ebd
@ -51,7 +51,8 @@ def fetch_servers(user: UserRecord) -> tuple[HTTPStatus, str or list]:
|
||||
if not servers_data:
|
||||
account_create(user)
|
||||
return HTTPStatus.OK, servers_data
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
file_manager.log_error(type(e).__name__, str(e))
|
||||
return account_create(user)
|
||||
|
||||
|
||||
@ -69,6 +70,7 @@ def account_create(user: UserRecord) -> tuple[HTTPStatus, str or None]:
|
||||
})
|
||||
return HTTPStatus.CREATED, "Successfully created account."
|
||||
except Exception as e:
|
||||
file_manager.log_error(type(e).__name__, str(e))
|
||||
return HTTPStatus.INTERNAL_SERVER_ERROR, "Error creating account."
|
||||
|
||||
|
||||
@ -99,6 +101,7 @@ def server_create(user: UserRecord, name: str, version: str, framework: str = "p
|
||||
file_manager.update_server_property(server_path + "/server.properties", "server-port", port)
|
||||
return HTTPStatus.CREATED, f"Successfully created server '{name}'."
|
||||
except Exception as e:
|
||||
file_manager.log_error(type(e).__name__, str(e))
|
||||
return HTTPStatus.INTERNAL_SERVER_ERROR, f"Server creation failed | {e}"
|
||||
|
||||
|
||||
@ -109,11 +112,12 @@ def server_delete(name: str, user: UserRecord) -> tuple[HTTPStatus, str or None]
|
||||
firebase_manager.delete_server(user_id, name)
|
||||
file_manager.delete_non_empty_folder(server_path)
|
||||
return HTTPStatus.OK, f"Successfully deleted server {name}."
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
file_manager.log_error(type(e).__name__, str(e))
|
||||
return HTTPStatus.INTERNAL_SERVER_ERROR, None
|
||||
|
||||
|
||||
def account_delete(user: UserRecord, subdomain: str) -> tuple[HTTPStatus, str or None]:
|
||||
def account_delete(user: UserRecord) -> tuple[HTTPStatus, str or None]:
|
||||
user_id = user.uid
|
||||
try:
|
||||
dns_record_id = firebase_manager.get_user_field(user_id, "cloudflare_entry")
|
||||
@ -145,10 +149,11 @@ def server_run(user: UserRecord, name: str) -> tuple[HTTPStatus, str or None]:
|
||||
try:
|
||||
firebase_manager.update_server_running_state(user_id, name, True)
|
||||
except Exception as e:
|
||||
return HTTPStatus.INTERNAL_SERVER_ERROR, f"Error updating server {name}'s running state in database. {type(e).__name__}{str(e)}."
|
||||
return HTTPStatus.INTERNAL_SERVER_ERROR, (f"Error updating server {name}'s running state in database. "
|
||||
f"{type(e).__name__}{str(e)}.")
|
||||
return HTTPStatus.ACCEPTED, f"Successfully started server {name}."
|
||||
except Exception as e:
|
||||
print(f"Error when running server: {e}")
|
||||
file_manager.log_error(type(e).__name__, str(e))
|
||||
return HTTPStatus.INTERNAL_SERVER_ERROR, f"Error when running server: {e}"
|
||||
|
||||
|
||||
@ -164,6 +169,7 @@ def server_stop(user: UserRecord, name: str) -> tuple[HTTPStatus, str or None]:
|
||||
return HTTPStatus.OK, f"Successfully stopped server {name}."
|
||||
return HTTPStatus.OK, f"Server {name} already stopped."
|
||||
except Exception as e:
|
||||
file_manager.log_error(type(e).__name__, str(e))
|
||||
if port:
|
||||
mc_manager.stop_server_forcefully(port)
|
||||
return HTTPStatus.OK, f"Successfully stopped server {name}."
|
||||
@ -182,6 +188,7 @@ def update_property(uid: str, name: str, prop: str, value: str) -> tuple[HTTPSta
|
||||
except FileNotFoundError:
|
||||
return HTTPStatus.NOT_FOUND, f"File server.properties for server '{name}' not found."
|
||||
except Exception as e:
|
||||
file_manager.log_error(type(e).__name__, str(e))
|
||||
return HTTPStatus.INTERNAL_SERVER_ERROR, f"Unhandled error: {type(e).__name__}, {str(e)}"
|
||||
|
||||
|
||||
@ -206,7 +213,7 @@ def run_command(user: UserRecord, command: str, name: str) -> tuple[HTTPStatus,
|
||||
mc_manager.execute_server_command(port, command)
|
||||
return HTTPStatus.OK, f"Command '{command}' executed successfully."
|
||||
except Exception as e:
|
||||
print(f"Error executing command: {e}")
|
||||
file_manager.log_error(type(e).__name__, str(e))
|
||||
return HTTPStatus.INTERNAL_SERVER_ERROR, f"Error executing command: {command} || {str(e)}"
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user