sp-hydra-veil-core/core/models/Result.py

79 lines
2.6 KiB
Python

from core.services.networking.api_requests.ApiResponseModel import BackoffStrategy
from enum import Enum
from dataclasses import dataclass
from typing import Optional, Any
from functools import partial
class ResultError(Enum):
"""Classified error categories."""
SUCCESS = "success"
NOT_SUPPORTED = "NOT_SUPPORTED"
INVALID_INPUT = "invalid_input"
MISSING_FILE = "missing_file"
MISSING_DEPENDENCY = "missing_dependency"
MISSING_DATA = "missing_data"
MISSING_SOFTWARE = "missing_software"
FILE_SYSTEM = "filesystem"
CONNECTION = "connection"
DATABASE = "database"
PERMISSION = "permission"
SUBSCRIPTION = "subscription"
EXPIRED_INVOICE = "expired_invoice" # meant for invoice
UNPAID = "unpaid"
EXPIRED_SUB = "expired_sub"
ACTIVE_BILLING = "active_billing"
BILLING_CONFLICT = "billing_conflict"
STATE_CONFLICT = "state_conflict"
ZOMBIE_CONNECTION = "zombie_connection"
TICKET = "ticket"
NO_TICKET = "no_ticket"
RANDOM_TICKETS_OFF = "random_tickets_off"
TICKET_SETUP = "ticket_setup"
TICKET_EXPIRED = "ticket_expired"
ALREADY_EXISTS = "already_exists"
BILLING_CODE_EXISTS = "billing_code_exists"
PROCESS_GOT_KILLED = "process_got_killed"
PROCESS_WONT_START = "process_wont_start"
PROCESS_MISMATCH = "process_mismatch"
NMCLI = "nmcli_issues"
FIREWALL = "firewall"
CLIENT_DNS = "client_dns"
EXTERNAL_DNS = "external_dns"
INTERFACE = "interface"
TIMEOUT = "timeout"
INVALID_API_REPLY = "invalid_api_reply"
ENCRYPTION = "encryption"
ENDPOINT_VERIFICATION = "endpoint_verification"
LEAK_ISSUE = "leak_issue"
NEED_SYNC = "need_sync"
WRONG_LOCATION = "wrong_location"
SERVER_SIDE = "server_side"
MTU = "mtu"
TOR_NEEDED = "tor_needed"
API_DOWN = "api_down"
NODE_ERROR = "node_error"
NO_INTERNET = "no_internet"
NAVIGATE_TO = "navigate_to"
UNKNOWN = "unknown"
@dataclass
class Result():
valid: bool
goal_result: Optional[bool] = None
error_type: ResultError = ResultError.SUCCESS
data: Optional[Any] = None
message: Optional[str] = None
goal: Optional[str] = None
backoff_strategy: Optional[BackoffStrategy] = None
function_choice: Optional[partial] = None
no_option: Optional[partial] = None
navigate_to: Optional[str] = None
# def user_message(self) -> str:
# """Human-readable error for the UI."""
# messages = {
# ResultError.SUCCESS: "Operation completed successfully.",
# ResultError.UNKNOWN: f"Error: {self.message}",
# }
# return messages.get(self.error_type, "Unknown error")