Abandon fetching offline presence on 400 error
It seems like some servers return a M_UNRECOGNIZED code instead of M_FORBIDDEN or "offline" when trying to fetch the presence for a user and it's not available. Fixes https://github.com/mirukana/mirage/issues/116
This commit is contained in:
parent
a9c316fcf5
commit
32679aa7f8
|
@ -33,6 +33,12 @@ class MatrixError(Exception):
|
||||||
return cls(response.transport_response.status, response.status_code)
|
return cls(response.transport_response.status, response.status_code)
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class MatrixUnrecognized(MatrixError):
|
||||||
|
http_code: int = 400
|
||||||
|
m_code: str = "M_UNRECOGNIZED"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class MatrixInvalidAccessToken(MatrixError):
|
class MatrixInvalidAccessToken(MatrixError):
|
||||||
http_code: int = 401
|
http_code: int = 401
|
||||||
|
|
|
@ -37,7 +37,7 @@ from . import __app_name__, __display_name__, utils
|
||||||
from .errors import (
|
from .errors import (
|
||||||
BadMimeType, InvalidUserId, InvalidUserInContext, MatrixBadGateway,
|
BadMimeType, InvalidUserId, InvalidUserInContext, MatrixBadGateway,
|
||||||
MatrixError, MatrixForbidden, MatrixInvalidAccessToken, MatrixNotFound,
|
MatrixError, MatrixForbidden, MatrixInvalidAccessToken, MatrixNotFound,
|
||||||
MatrixTooLarge, MatrixUnauthorized, UneededThumbnail,
|
MatrixTooLarge, MatrixUnauthorized, MatrixUnrecognized, UneededThumbnail,
|
||||||
UserFromOtherServerDisallowed,
|
UserFromOtherServerDisallowed,
|
||||||
)
|
)
|
||||||
from .html_markdown import HTML_PROCESSOR as HTML
|
from .html_markdown import HTML_PROCESSOR as HTML
|
||||||
|
@ -1474,7 +1474,7 @@ class MatrixClient(nio.AsyncClient):
|
||||||
try:
|
try:
|
||||||
async with self.backend.concurrent_get_presence_limit:
|
async with self.backend.concurrent_get_presence_limit:
|
||||||
resp = await self.get_presence(user_id)
|
resp = await self.get_presence(user_id)
|
||||||
except MatrixForbidden:
|
except (MatrixForbidden, MatrixUnrecognized):
|
||||||
return
|
return
|
||||||
|
|
||||||
await self.nio_callbacks.onPresenceEvent(nio.PresenceEvent(
|
await self.nio_callbacks.onPresenceEvent(nio.PresenceEvent(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user