فهرست منبع

report authorization failure when send message fails with AuthorizationFailedException

Sumner Evans 3 سال پیش
والد
کامیت
80e543fa07
1فایلهای تغییر یافته به همراه11 افزوده شده و 1 حذف شده
  1. 11 1
      mautrix_signal/portal.py

+ 11 - 1
mautrix_signal/portal.py

@@ -13,6 +13,7 @@
 #
 #
 # You should have received a copy of the GNU Affero General Public License
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
+from mautrix.util.bridge_state import BridgeStateEvent
 from typing import (Dict, Tuple, Optional, List, Deque, Any, Union, AsyncGenerator, Awaitable, Set,
 from typing import (Dict, Tuple, Optional, List, Deque, Any, Union, AsyncGenerator, Awaitable, Set,
                     Callable, TYPE_CHECKING, cast)
                     Callable, TYPE_CHECKING, cast)
 from html import escape as escape_html
 from html import escape as escape_html
@@ -30,7 +31,7 @@ import os
 from mausignald.types import (Address, MessageData, Reaction, Quote, Group, Contact, Profile,
 from mausignald.types import (Address, MessageData, Reaction, Quote, Group, Contact, Profile,
                               Attachment, GroupID, GroupV2ID, GroupV2, Mention, Sticker,
                               Attachment, GroupID, GroupV2ID, GroupV2, Mention, Sticker,
                               GroupAccessControl, AccessControlMode, GroupMemberRole)
                               GroupAccessControl, AccessControlMode, GroupMemberRole)
-from mausignald.errors import RPCError
+from mausignald.errors import AuthorizationFailedException, RPCError, ResponseError
 from mautrix.appservice import AppService, IntentAPI
 from mautrix.appservice import AppService, IntentAPI
 from mautrix.bridge import BasePortal, async_getter_lock
 from mautrix.bridge import BasePortal, async_getter_lock
 from mautrix.types import (EventID, MessageEventContent, RoomID, EventType, MessageType, Format,
 from mautrix.types import (EventID, MessageEventContent, RoomID, EventType, MessageType, Format,
@@ -291,6 +292,15 @@ class Portal(DBPortal, BasePortal):
                                    mentions=mentions, quote=quote, attachments=attachments,
                                    mentions=mentions, quote=quote, attachments=attachments,
                                    timestamp=request_id)
                                    timestamp=request_id)
         except Exception as e:
         except Exception as e:
+            authroization_failed_exception = (
+                "org.whispersystems.signalservice.api.push.exceptions.AuthorizationFailedException"
+            )
+            if isinstance(e, ResponseError):
+                if authroization_failed_exception in e.data.get("exceptions"):
+                    await sender.push_bridge_state(
+                        BridgeStateEvent.BAD_CREDENTIALS,
+                        error=str(e),
+                    )
             await self._send_message(
             await self._send_message(
                 self.main_intent,
                 self.main_intent,
                 TextMessageEventContent(
                 TextMessageEventContent(