Mercurial > libervia-backend
comparison libervia/backend/plugins/plugin_comp_ap_gateway/__init__.py @ 4169:e92c32014024
component AP gateway: log a warning instead of raising an exception in `onMessage`:
if something goes wrong, a warning is logged instead of raising a failing in `onMessage`'s
`get_ap_actor_id_from_account` and `sign_and_post` calls.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 01 Dec 2023 18:22:26 +0100 |
parents | a1f7040b5a15 |
children | 6784d07b99c8 |
comparison
equal
deleted
inserted
replaced
4168:d67eaa684484 | 4169:e92c32014024 |
---|---|
2275 f"ignoring message addressed to gateway itself: {mess_data}" | 2275 f"ignoring message addressed to gateway itself: {mess_data}" |
2276 ) | 2276 ) |
2277 return mess_data | 2277 return mess_data |
2278 | 2278 |
2279 actor_account = self._e.unescape(mess_data["to"].user) | 2279 actor_account = self._e.unescape(mess_data["to"].user) |
2280 actor_id = await self.get_ap_actor_id_from_account(actor_account) | 2280 try: |
2281 actor_id = await self.get_ap_actor_id_from_account(actor_account) | |
2282 except Exception as e: | |
2283 log.warning( | |
2284 f"Can't retrieve data on actor {actor_account}: {e}" | |
2285 ) | |
2286 # TODO: send an error <message> | |
2287 return mess_data | |
2281 inbox = await self.get_ap_inbox_from_id(actor_id, use_shared=False) | 2288 inbox = await self.get_ap_inbox_from_id(actor_id, use_shared=False) |
2282 | 2289 |
2283 try: | 2290 try: |
2284 language, message = next(iter(mess_data["message"].items())) | 2291 language, message = next(iter(mess_data["message"].items())) |
2285 except (KeyError, StopIteration): | 2292 except (KeyError, StopIteration): |
2311 "type": TYPE_MENTION, | 2318 "type": TYPE_MENTION, |
2312 "href": actor_id, | 2319 "href": actor_id, |
2313 "name": f"@{actor_account}", | 2320 "name": f"@{actor_account}", |
2314 }) | 2321 }) |
2315 | 2322 |
2316 await self.sign_and_post(inbox, ap_item["actor"], ap_item) | 2323 try: |
2324 await self.sign_and_post(inbox, ap_item["actor"], ap_item) | |
2325 except Exception as e: | |
2326 # TODO: send an error <message> | |
2327 log.warning( | |
2328 f"Can't send message to {inbox}: {e}" | |
2329 ) | |
2317 return mess_data | 2330 return mess_data |
2318 | 2331 |
2319 async def _on_message_retract( | 2332 async def _on_message_retract( |
2320 self, | 2333 self, |
2321 client: SatXMPPEntity, | 2334 client: SatXMPPEntity, |