Browse Source

Improve handling logouts in backfill loop

Tulir Asokan 2 years ago
parent
commit
a0f601ae07
1 changed files with 7 additions and 13 deletions
  1. 7 13
      mautrix_instagram/user.py

+ 7 - 13
mautrix_instagram/user.py

@@ -1,5 +1,5 @@
 # mautrix-instagram - A Matrix-Instagram puppeting bridge.
 # mautrix-instagram - A Matrix-Instagram puppeting bridge.
-# Copyright (C) 2022 Tulir Asokan
+# Copyright (C) 2023 Tulir Asokan
 #
 #
 # This program is free software: you can redistribute it and/or modify
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as published by
 # it under the terms of the GNU Affero General Public License as published by
@@ -29,7 +29,6 @@ from mauigpapi.errors import (
     IGChallengeError,
     IGChallengeError,
     IGCheckpointError,
     IGCheckpointError,
     IGConsentRequiredError,
     IGConsentRequiredError,
-    IGLoginRequiredError,
     IGNotLoggedInError,
     IGNotLoggedInError,
     IGRateLimitError,
     IGRateLimitError,
     IGUserIDNotFoundError,
     IGUserIDNotFoundError,
@@ -318,18 +317,13 @@ class User(DBUser, BaseUser):
                 await req.mark_dispatched()
                 await req.mark_dispatched()
                 await portal.backfill(self, req)
                 await portal.backfill(self, req)
                 await req.mark_done()
                 await req.mark_done()
-            except IGLoginRequiredError as e:
-                self.log.exception(
-                    "User is logged out. Stopping backfill requests loop and forcing refresh."
-                )
-                await self.refresh(resync=False)
+            except IGNotLoggedInError as e:
+                self.log.exception("User got logged out during backfill loop")
+                await self.logout(error=e)
                 break
                 break
-            except IGChallengeError as e:
-                self.log.exception(
-                    "User received a challenge. Stopping backfill requests loop and "
-                    "forcing refresh."
-                )
-                await self.refresh(resync=False)
+            except (IGChallengeError, IGConsentRequiredError) as e:
+                self.log.exception("User got a challenge during backfill loop")
+                await self._handle_checkpoint(e, on="backfill")
                 break
                 break
             except Exception as e:
             except Exception as e:
                 self.log.exception("Failed to backfill portal %s: %s", req.portal_thread_id, e)
                 self.log.exception("Failed to backfill portal %s: %s", req.portal_thread_id, e)