|
@@ -7,6 +7,8 @@ from __future__ import annotations
|
|
|
|
|
|
from typing import Any
|
|
from typing import Any
|
|
|
|
|
|
|
|
+from mautrix.util.format_duration import format_duration
|
|
|
|
+
|
|
|
|
|
|
class RPCError(Exception):
|
|
class RPCError(Exception):
|
|
pass
|
|
pass
|
|
@@ -118,6 +120,20 @@ class GroupPatchNotAcceptedError(ResponseError):
|
|
pass
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
+class ProofRequiredError(ResponseError):
|
|
|
|
+ def __init__(self, data: dict[str, Any]) -> None:
|
|
|
|
+ self.options = data.get("options")
|
|
|
|
+ self.retry_after = data.get("retry_after")
|
|
|
|
+ self.token = data.get("token")
|
|
|
|
+ message = "You have been rate limited by Signal."
|
|
|
|
+ if isinstance(self.retry_after, (int, float)):
|
|
|
|
+ message += (
|
|
|
|
+ f" Try again in {format_duration(int(self.retry_after))} "
|
|
|
|
+ "or complete a captcha challenge using the `submit-challenge` command."
|
|
|
|
+ )
|
|
|
|
+ super().__init__(data, message_override=message)
|
|
|
|
+
|
|
|
|
+
|
|
response_error_types = {
|
|
response_error_types = {
|
|
"invalid_request": RequestValidationFailure,
|
|
"invalid_request": RequestValidationFailure,
|
|
"TimeoutException": TimeoutException,
|
|
"TimeoutException": TimeoutException,
|
|
@@ -134,6 +150,7 @@ response_error_types = {
|
|
"ProfileUnavailableError": ProfileUnavailableError,
|
|
"ProfileUnavailableError": ProfileUnavailableError,
|
|
"NoSuchAccountError": NoSuchAccountError,
|
|
"NoSuchAccountError": NoSuchAccountError,
|
|
"GroupPatchNotAcceptedError": GroupPatchNotAcceptedError,
|
|
"GroupPatchNotAcceptedError": GroupPatchNotAcceptedError,
|
|
|
|
+ "ProofRequiredError": ProofRequiredError,
|
|
# TODO add rest from https://gitlab.com/signald/signald/-/tree/main/src/main/java/io/finn/signald/clientprotocol/v1/exceptions
|
|
# TODO add rest from https://gitlab.com/signald/signald/-/tree/main/src/main/java/io/finn/signald/clientprotocol/v1/exceptions
|
|
}
|
|
}
|
|
|
|
|