Browse Source

Retry non-JSON responses when getting current user

Nick Barrett 2 years ago
parent
commit
f3aeb8daba
1 changed files with 11 additions and 0 deletions
  1. 11 0
      mautrix_instagram/user.py

+ 11 - 0
mautrix_instagram/user.py

@@ -29,6 +29,7 @@ from mauigpapi.errors import (
     IGConsentRequiredError,
     IGConsentRequiredError,
     IGNotLoggedInError,
     IGNotLoggedInError,
     IGRateLimitError,
     IGRateLimitError,
+    IGUnknownError,
     IGUserIDNotFoundError,
     IGUserIDNotFoundError,
     IrisSubscribeError,
     IrisSubscribeError,
     MQTTConnectionUnauthorized,
     MQTTConnectionUnauthorized,
@@ -888,6 +889,16 @@ class User(DBUser, BaseUser):
             except (IGChallengeError, IGConsentRequiredError) as e:
             except (IGChallengeError, IGConsentRequiredError) as e:
                 await self._handle_checkpoint(e, on="reconnect")
                 await self._handle_checkpoint(e, on="reconnect")
                 return
                 return
+            except IGUnknownError as e:
+                if "non-JSON body" not in e:
+                    raise
+                errors += 1
+                if errors > 10:
+                    raise
+                self.log.warning(
+                    "Non-JSON body while trying to check user for reconnection, retrying in 10s"
+                )
+                await asyncio.sleep(10)
             except Exception as e:
             except Exception as e:
                 self.log.exception("Error while reconnecting to Instagram")
                 self.log.exception("Error while reconnecting to Instagram")
                 if isinstance(e, IGCheckpointError):
                 if isinstance(e, IGCheckpointError):