register_server: Improve UX with the "hostname already in use" error.

An even better way than the current json error message recommending the
--registration-transfer option is to return an appropriate error code
and have that get picked up by the register_server command.

The register_server command can then display a more comprehensive,
better formatted error message with proper whitespaces and a pointer to
the documentation.
This commit is contained in:
Mateusz Mandera
2025-01-29 20:53:46 +08:00
committed by Tim Abbott
parent 6d555b01d0
commit ddcc36c3aa
5 changed files with 38 additions and 14 deletions

View File

@@ -1528,3 +1528,19 @@ class InvalidRemotePushDeviceTokenError(JsonableError):
class PushNotificationsDisallowedByBouncerError(Exception):
def __init__(self, reason: str) -> None:
self.reason = reason
class HostnameAlreadyInUseBouncerError(JsonableError):
code = ErrorCode.HOSTNAME_ALREADY_IN_USE_BOUNCER_ERROR
data_fields = ["hostname"]
def __init__(self, hostname: str) -> None:
self.hostname: str = hostname
@staticmethod
@override
def msg_format() -> str:
# This message is not read by any of the client apps, just potentially displayed
# via server administration tools, so it doesn't need translations.
return "A server with hostname {hostname} already exists"