mirror of
https://github.com/TronoSfera/backup_service.git
synced 2026-05-18 10:03:32 +03:00
Improve client registration error reporting
This commit is contained in:
parent
d4256d6d77
commit
a98a485145
1 changed files with 11 additions and 9 deletions
|
|
@ -44,7 +44,7 @@ import sys
|
||||||
import time
|
import time
|
||||||
from dataclasses import dataclass, asdict
|
from dataclasses import dataclass, asdict
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Dict, Optional, List
|
from typing import Dict, Optional, List, Tuple
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
import yaml # type: ignore
|
import yaml # type: ignore
|
||||||
|
|
@ -402,7 +402,7 @@ class BackupClient:
|
||||||
password: str,
|
password: str,
|
||||||
client_name: str,
|
client_name: str,
|
||||||
monitored_paths: List[str],
|
monitored_paths: List[str],
|
||||||
) -> Optional[int]:
|
) -> Tuple[Optional[int], Optional[str]]:
|
||||||
"""
|
"""
|
||||||
Apply a new configuration provided by the user via the web UI.
|
Apply a new configuration provided by the user via the web UI.
|
||||||
|
|
||||||
|
|
@ -417,8 +417,9 @@ class BackupClient:
|
||||||
client_name: Human‑readable name for this client.
|
client_name: Human‑readable name for this client.
|
||||||
monitored_paths: List of directory paths to back up.
|
monitored_paths: List of directory paths to back up.
|
||||||
Returns:
|
Returns:
|
||||||
The numeric client ID assigned by the server, or ``None`` if
|
A tuple of (client_id, error_message). ``client_id`` is the
|
||||||
registration fails.
|
numeric client ID assigned by the server on success; otherwise
|
||||||
|
``None`` and a human-readable error message are returned.
|
||||||
"""
|
"""
|
||||||
# Update attributes
|
# Update attributes
|
||||||
self.server_url = server_url.strip()
|
self.server_url = server_url.strip()
|
||||||
|
|
@ -439,11 +440,11 @@ class BackupClient:
|
||||||
self._register_client()
|
self._register_client()
|
||||||
# Save state to disk
|
# Save state to disk
|
||||||
self._save_state()
|
self._save_state()
|
||||||
return self.state.client_id
|
return self.state.client_id, None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Log any error; the backup loop will skip operations until configured
|
# Log any error; the backup loop will skip operations until configured
|
||||||
self.send_log(level="ERROR", message=str(e))
|
self.send_log(level="ERROR", message=str(e))
|
||||||
return None
|
return None, str(e)
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
"""
|
"""
|
||||||
|
|
@ -612,7 +613,7 @@ def create_app(client: BackupClient) -> FastAPI:
|
||||||
|
|
||||||
# Apply configuration and attempt to register the client. apply_config
|
# Apply configuration and attempt to register the client. apply_config
|
||||||
# returns the client_id if registration succeeds.
|
# returns the client_id if registration succeeds.
|
||||||
client_id = client.apply_config(
|
client_id, error_message = client.apply_config(
|
||||||
server_url=server_url,
|
server_url=server_url,
|
||||||
username=username,
|
username=username,
|
||||||
password=password,
|
password=password,
|
||||||
|
|
@ -630,6 +631,7 @@ def create_app(client: BackupClient) -> FastAPI:
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
# If registration failed, re-render the form with a generic error message
|
# If registration failed, re-render the form with a generic error message
|
||||||
|
error_message = error_message or "Failed to authenticate or register. Please check your credentials and server address."
|
||||||
return templates.TemplateResponse(
|
return templates.TemplateResponse(
|
||||||
"login.html",
|
"login.html",
|
||||||
{
|
{
|
||||||
|
|
@ -638,7 +640,7 @@ def create_app(client: BackupClient) -> FastAPI:
|
||||||
"username": username,
|
"username": username,
|
||||||
"client_name": client_name,
|
"client_name": client_name,
|
||||||
"monitored_paths": monitored_paths,
|
"monitored_paths": monitored_paths,
|
||||||
"error": "Failed to authenticate or register. Please check your credentials and server address.",
|
"error": error_message,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -685,4 +687,4 @@ if __name__ == "__main__":
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
# Configuration is provided via environment variables. Start the
|
# Configuration is provided via environment variables. Start the
|
||||||
# backup loop immediately.
|
# backup loop immediately.
|
||||||
client.run()
|
client.run()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue